def syncplugins(plugmgr, existing, createfn, deletefn):
    """
    Helper function for syncing plugins. Backend agnostic - all backend
    functionality is passed through ``deletefn`` and ``createfn``

    plugmgr     - Plugin manager used
    existing    - A list of existing plugins. Each item needs to have ``type``,
                  ``name``, and ``run`` attributes.
    deletefn    - Deletion function. This will be called when the plugin should
                  be deleted. It takes one argument - the deleted plugin. This
                  will be an item from the ``existing`` list.
    createfn    - Function used to create new plugin. It should take one
                  argument - ``PluginDesc`` with description of the new plugin.
    """
    plugmgr.discover()
    newsnipers = list(plugmgr.iter())
    for plugin in existing:
        if plugmgr.find(plugin.type, plugin.name):
            plug_eq = lambda x: x.type != plugin.type or x.name != plugin.name
            newsnipers = filter(plug_eq, newsnipers)
        else:
            deletefn(plugin)
    for sniper in newsnipers:
        createfn(sniper)
