diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-01 09:48:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-01 09:48:19 +0300 |
commit | c6d43a02cb30aafaa594c8dba0b540f8c54299b8 (patch) | |
tree | 04ebc380e2a3d0c2430955ad0da8d34f4ef77413 /release/scripts/ui/space_userpref.py | |
parent | 6f0aa2cb0ed6b42d284d8352e697a4e4b5c2ebc5 (diff) |
bugfix [#25767] Addons cannot be upgraded through the UI
added option to overwrite.
Diffstat (limited to 'release/scripts/ui/space_userpref.py')
-rw-r--r-- | release/scripts/ui/space_userpref.py | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 20c5b1c93f4..c7dce5008f8 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -1150,13 +1150,27 @@ class WM_OT_addon_install(bpy.types.Operator): bl_idname = "wm.addon_install" bl_label = "Install Add-On..." - module = StringProperty(name="Module", description="Module name of the addon to disable") + overwrite = BoolProperty(name="Overwrite", description="Remove existing addons with the same ID", default=True) filepath = StringProperty(name="File Path", description="File path to write file to") filter_folder = BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'}) filter_python = BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'}) filter_glob = StringProperty(default="*.py;*.zip", options={'HIDDEN'}) + @staticmethod + def _module_remove(path_addons, module): + module = os.path.splitext(module)[0] + for f in os.listdir(path_addons): + f_base = os.path.splitext(f)[0] + if f_base == module: + f_full = os.path.join(path_addons, f) + + if os.path.isdir(f_full): + os.rmdir(f_full) + else: + os.remove(f_full) + + def execute(self, context): import traceback import zipfile @@ -1175,10 +1189,22 @@ class WM_OT_addon_install(bpy.types.Operator): if zipfile.is_zipfile(pyfile): try: file_to_extract = zipfile.ZipFile(pyfile, 'r') + except: + traceback.print_exc() + return {'CANCELLED'} - #extract the file to "addons" - file_to_extract.extractall(path_addons) + if self.overwrite: + for f in file_to_extract.namelist(): + __class__._module_remove(path_addons, f) + else: + for f in file_to_extract.namelist(): + path_dest = os.path.join(path_addons, os.path.basename(f)) + if os.path.exists(path_dest): + self.report({'WARNING'}, "File already installed to %r\n" % path_dest) + return {'CANCELLED'} + try: # extract the file to "addons" + file_to_extract.extractall(path_addons) except: traceback.print_exc() return {'CANCELLED'} @@ -1186,9 +1212,12 @@ class WM_OT_addon_install(bpy.types.Operator): else: path_dest = os.path.join(path_addons, os.path.basename(pyfile)) - if os.path.exists(path_dest): + if self.overwrite: + __class__._module_remove(path_addons, os.path.basename(pyfile)) + elif os.path.exists(path_dest): self.report({'WARNING'}, "File already installed to %r\n" % path_dest) return {'CANCELLED'} + #if not compressed file just copy into the addon path try: |