'Obtains a plugin report -
cms.management.commands.subcommands.list.plugin_report - and uses it
to delete orphaned plugins from the database, i.e. ones that are no
longer installed, and ones that have no corresponding saved plugin
instances (as will happen if a plugin is inserted into a placeholder,
but not saved).'

def handle(self, *args, **options):

    self.stdout.write(u'Obtaining    plugin    report\n')
    uninstalled_instances = []
    unsaved_instances = []
    for plugin in plugin_report():
        if (not plugin[u'model']):
            for instance in plugin[u'instances']:
                uninstalled_instances.append(instance)
        for instance in plugin[u'unsaved_instances']:
            unsaved_instances.append(instance)
    if options.get(u'interactive'):
        confirm = input((u"\nYou    have    requested    to    delete    any    instances    of    uninstalled    plugins    and    empty    plugin    instances.\nThere    are    %d    uninstalled    plugins    and    %d    empty    plugins.\nAre    you    sure    you    want    to    do    this?\nType    'yes'    to    continue,    or    'no'    to    cancel:    " % (len(uninstalled_instances), len(unsaved_instances))))
    else:
        confirm = u'yes'
    if (confirm == u'yes'):
        self.stdout.write(u'...    deleting    any    instances    of    uninstalled    plugins    and    empty    plugin    instances\n')
        for instance in uninstalled_instances:
            instance.delete()
        for instance in unsaved_instances:
            instance.delete()
        self.stdout.write((u'Deleted    instances    of:    \n                %s    uninstalled    plugins        \n                %s    plugins    with    unsaved    instances\n' % (len(uninstalled_instances), len(unsaved_instances))))
        self.stdout.write(u'all    done\n')
