Browse Source

Starts implementation of uninstall plugins action

For the moment there is only uninstalling by name that works because #207
Yann Weber 8 years ago
parent
commit
08bcdbe57b
1 changed files with 54 additions and 6 deletions
  1. 54
    6
      lodel/plugin/core_scripts.py

+ 54
- 6
lodel/plugin/core_scripts.py View File

88
             default = list(),
88
             default = list(),
89
             help="Indicate a plugin name to uninstall",
89
             help="Indicate a plugin name to uninstall",
90
             type=str)
90
             type=str)
91
-        parser.add_argument('-f', '--file', nargs='*',
91
+        parser.add_argument('-a', '--archive', nargs='*',
92
             default = list(),
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
             type=str)
95
             type=str)
95
         parser.add_argument('-d', '--directory', nargs='*',
96
         parser.add_argument('-d', '--directory', nargs='*',
96
             default = list(),
97
             default = list(),
97
             help="Specify a plugin by its directory",
98
             help="Specify a plugin by its directory",
98
             type=str)
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
     @classmethod
103
     @classmethod
101
     def run(cls, args):
104
     def run(cls, args):
102
         if args.clean:
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
                 raise RuntimeError("When using -c --clean option you can \
108
                 raise RuntimeError("When using -c --clean option you can \
105
 only use option -n --name to clean plugins with specified names")
109
 only use option -n --name to clean plugins with specified names")
106
             return cls.clean(args)
110
             return cls.clean(args)
119
 We do not know where to find it...")
123
 We do not know where to find it...")
120
         plist = Plugin.discover()
124
         plist = Plugin.discover()
121
         errors = dict()
125
         errors = dict()
122
-        if len(args.file) > 0:
126
+        if len(args.archive) > 0:
123
             raise NotImplementedError("Not supported yet")
127
             raise NotImplementedError("Not supported yet")
124
         
128
         
125
         plugins_infos = {}
129
         plugins_infos = {}
178
             print(msg)
182
             print(msg)
179
     
183
     
180
     ##@brief Handles plugins uninstall
184
     ##@brief Handles plugins uninstall
185
+    #@todo uninstall by path is broken
181
     @classmethod
186
     @classmethod
182
     def uninstall(cls, args):
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
     ##@brief Handles plugins clean
233
     ##@brief Handles plugins clean
186
     @classmethod
234
     @classmethod
187
     def clean(cls, args):
235
     def clean(cls, args):
188
         import lodel.plugin.plugins
236
         import lodel.plugin.plugins
189
         from lodel.plugin.plugins import Plugin
237
         from lodel.plugin.plugins import Plugin
190
-        if len(args.file) > 0:
238
+        if len(args.archive) > 0:
191
             raise RuntimeError("Cannot specify plugins to uninstall using \
239
             raise RuntimeError("Cannot specify plugins to uninstall using \
192
 -f --file option. You have to use -d --directory or -n --name")
240
 -f --file option. You have to use -d --directory or -n --name")
193
         if len(args.plugin_name) > 0:
241
         if len(args.plugin_name) > 0:

Loading…
Cancel
Save