瀏覽代碼

Starts implementation of uninstall plugins action

For the moment there is only uninstalling by name that works because #207
Yann Weber 7 年之前
父節點
當前提交
08bcdbe57b
共有 1 個文件被更改,包括 54 次插入6 次删除
  1. 54
    6
      lodel/plugin/core_scripts.py

+ 54
- 6
lodel/plugin/core_scripts.py 查看文件

@@ -88,19 +88,23 @@ class PluginManager(lodel_script.LodelScript):
88 88
             default = list(),
89 89
             help="Indicate a plugin name to uninstall",
90 90
             type=str)
91
-        parser.add_argument('-f', '--file', nargs='*',
91
+        parser.add_argument('-a', '--archive', nargs='*',
92 92
             default = list(),
93
-            help="Specify a tarball containing a plugin to install",
93
+            help="(NOT IMPLEMENTED) Specify a tarball containing a plugin \
94
+to install",
94 95
             type=str)
95 96
         parser.add_argument('-d', '--directory', nargs='*',
96 97
             default = list(),
97 98
             help="Specify a plugin by its directory",
98 99
             type=str)
100
+        parser.add_argument('-f', '--force', action="store_true",
101
+            help="Force plugin directory deletion in case of check errors")
99 102
 
100 103
     @classmethod
101 104
     def run(cls, args):
102 105
         if args.clean:
103
-            if args.uninstall or len(args.directory) > 0 or len(args.file) > 0:
106
+            if args.uninstall or len(args.directory) > 0 \
107
+                    or len(args.archive) > 0:
104 108
                 raise RuntimeError("When using -c --clean option you can \
105 109
 only use option -n --name to clean plugins with specified names")
106 110
             return cls.clean(args)
@@ -119,7 +123,7 @@ only use option -n --name to clean plugins with specified names")
119 123
 We do not know where to find it...")
120 124
         plist = Plugin.discover()
121 125
         errors = dict()
122
-        if len(args.file) > 0:
126
+        if len(args.archive) > 0:
123 127
             raise NotImplementedError("Not supported yet")
124 128
         
125 129
         plugins_infos = {}
@@ -178,16 +182,60 @@ in %s" % (orig_path, dst_path))
178 182
             print(msg)
179 183
     
180 184
     ##@brief Handles plugins uninstall
185
+    #@todo uninstall by path is broken
181 186
     @classmethod
182 187
     def uninstall(cls, args):
183
-        raise NotImplementedError("Not yet implemented")
188
+        import lodel.plugin.plugins
189
+        from lodel.plugin.plugins import Plugin
190
+        if len(args.archive) > 0:
191
+            raise RuntimeError("Cannot uninstall plugin using -f --file \
192
+oprtions. Use -d --directory instead")
193
+        to_delete = dict() #Path to delete accumulator
194
+        errors = dict()
195
+        if len(args.directory) > 0:
196
+            #processing & checking -d --directory arguments
197
+            for path in args.directory:
198
+                apath = os.path.abspath(path)
199
+                if not apath.startswith(lodel.plugin.plugins.PLUGINS_PATH):
200
+                    errors[path] = "Not a subdir of %s"
201
+                    errors[path] %= lodel.plugin.plugins.PLUGINS_PATH
202
+                    continue
203
+                try:
204
+                    pinfos = Plugin.dir_is_plugin(apath)
205
+                except Exception as e:
206
+                    if not args.force:
207
+                        errors[path] = e
208
+                        continue
209
+                to_delete[path] = pinfos
210
+
211
+        if len(args.plugin_name) > 0:
212
+            #Processing -n --plugin-name arguments
213
+            plist = Plugin._discover(lodel.plugin.plugins.PLUGINS_PATH)
214
+            for pinfos in plist:
215
+                if pinfos['name'] in args.plugin_name:
216
+                    to_delete[pinfos['path']] = pinfos
217
+        
218
+        if len(errors) > 0:
219
+            msg = "Following errors detected before begining deletions :\n"
220
+            for path, errmsg in errors.items():
221
+                msg += "\t- For %s : %s" % (path, errmsg)
222
+            print(msg)
223
+            if not args.force:
224
+                exit(1)
225
+        
226
+        print("Begining deletion :")
227
+        for path, pinfos in to_delete.items():
228
+            #shutil.rmtree(path)
229
+            print("rm -R %s" % path)
230
+            print("\t%s(%s) in %s deleted" % (
231
+                pinfos['name'], pinfos['version'], pinfos['path']))
184 232
 
185 233
     ##@brief Handles plugins clean
186 234
     @classmethod
187 235
     def clean(cls, args):
188 236
         import lodel.plugin.plugins
189 237
         from lodel.plugin.plugins import Plugin
190
-        if len(args.file) > 0:
238
+        if len(args.archive) > 0:
191 239
             raise RuntimeError("Cannot specify plugins to uninstall using \
192 240
 -f --file option. You have to use -d --directory or -n --name")
193 241
         if len(args.plugin_name) > 0:

Loading…
取消
儲存