Beispiel #1
0
    def uninstall(cls, args):
        import lodel.plugin.plugins
        from lodel.plugin.plugins import Plugin
        if len(args.archive) > 0:
            raise RuntimeError("Cannot uninstall plugin using -f --file \
options. Use -d --directory instead")
        to_delete = dict()  # will contain all pathes of plugins to delete
        errors = dict()
        # Uninstall by pathes
        if len(args.directory) > 0:
            # processing & checking -d --directory arguments
            for path in args.directory:
                apath = os.path.abspath(path)
                # We assume plugins are in lodel/plugins
                if not apath.startswith(lodel.plugins.PLUGINS_PATH):
                    errors[path] = "Not a subdir of %s"
                    errors[path] %= lodel.plugins.PLUGINS_PATH
                    continue
                try:
                    pinfos = Plugin.dir_is_plugin(apath)
                except Exception as e:
                    if not args.force:
                        errors[path] = e
                        continue
                to_delete[path] = pinfos

        # Uninstall by plugin's names
        # We retrieve the path of the plugin from its name
        if len(args.plugin_name) > 0:
            # Processing -n --plugin-name arguments
            plist = Plugin._discover(lodel.plugins.PLUGINS_PATH)
            for pinfos in plist:
                if pinfos['name'] in args.plugin_name:
                    to_delete[pinfos['path']] = pinfos

        # Manage errors and exit if there is no force option
        if len(errors) > 0:
            msg = "Following errors detected before begining deletions :\n"
            for path, errmsg in errors.items():
                msg += "\t- For %s : %s" % (path, errmsg)
            print(msg)
            if not args.force:
                exit(1)

        print("Begining deletion :")
        for path, pinfos in to_delete.items():
            # shutil.rmtree(path)
            print("rm -R %s" % path)
            print("\t%s(%s) in %s deleted" % (
                pinfos['name'], pinfos['version'], pinfos['path']))
Beispiel #2
0
    def clean(cls, args):
        import lodel.plugin.plugins
        from lodel.plugin.plugins import Plugin
        if len(args.archive) > 0:
            raise RuntimeError("Cannot specify plugins to uninstall using \
-f --file option. You have to use -d --directory or -n --name")
        if len(args.plugin_name) > 0:
            names = args.plugin_name
        else:
            names = list(Plugin.discover().keys())

        #_discover do not remove duplicated names
        full_list = Plugin._discover(lodel.plugins.PLUGINS_PATH)

        # Casting into a dict with list of plugins infos
        pdict = dict()
        for pinfos in full_list:
            if pinfos['name'] in names:
                if pinfos['name'] in pdict:
                    pdict[pinfos['name']].append(pinfos)
                else:
                    pdict[pinfos['name']] = [pinfos]
        to_clean = list()
        clean_count = 0
        for pname, pinfos_l in pdict.items():
            if len(pinfos_l) > 1:
                # There are some plugins to clean
                tmp_l = sorted(pinfos_l, key=lambda item: item['version'])
                to_clean += tmp_l[:-1]
                msg = "Found %s(%s). Cleaning " % (
                    pname, tmp_l[-1]['version'])
                for pinfos in to_clean:
                    clean_count += 1
                    str_info = '%s(%s)' % (pname, pinfos['version'])
                    msg += "%s, " % (str_info)
                    shutil.rmtree(pinfos['path'])
                print(msg)
        if clean_count > 0:
            print("%d plugins were uninstalled" % clean_count)
        else:
            print("Already clean")
Beispiel #3
0
 def run(cls, args):
     import lodel.plugin.plugins
     from lodel.plugin.plugins import Plugin
     if args.verbose:
         #_discover does not return duplicated names
         tmp_plist = Plugin._discover(lodel.plugin.plugins.PLUGINS_PATH)
         plist = []
         # ordering the list by plugin's name
         for pname in sorted(set([d['name'] for d in tmp_plist])):
             for pinfos in tmp_plist:
                 if pinfos['name'] == pname:
                     plist.append(pinfos)
     else:
         # Retrieve the dict with the list of plugins
         pdict = Plugin.discover()
         # casting to a list ordered by names
         plist = []
         for pname in sorted(pdict.keys()):
             plist.append(pdict[pname])
     if args.csv:
         if args.verbose:
             res = "name,version,path\n"
             fmt = "%s,%s,%s\n"
         else:
             res = "name,version\n"
             fmt = "%s,%s\n"
     else:
         res = "Installed plugins list :\n"
         if args.verbose:
             fmt = "\t- %s(%s) in %s\n"
         else:
             fmt = "\t- %s(%s)\n"
     for pinfos in plist:
         if args.verbose:
             res += fmt % (
                 pinfos['name'], pinfos['version'], pinfos['path'])
         else:
             res += fmt % (pinfos['name'], pinfos['version'])
     print(res)