diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-28 01:36:37 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-28 01:36:37 +0300 |
commit | 7ab601747af702c43c03ff81e814bb3468dd8c9a (patch) | |
tree | 72af0f49ed18fd58978d7ca35e8d5cdc2febc040 | |
parent | 769eb45124596bff1c41e7e389b9110047b90d30 (diff) |
patch from Andy Braham with some modifications
extracts zipfiles when installing add-ons
-rw-r--r-- | release/scripts/ui/space_userpref.py | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 0526f1e99d4..bea9f80edec 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -1471,24 +1471,37 @@ class WM_OT_addon_install(bpy.types.Operator): def execute(self, context): import traceback + import zipfile pyfile = self.properties.path - paths = bpy.utils.script_paths("addons") - path_dest = os.path.join(paths[-1], os.path.basename(pyfile)) + path_addons = bpy.utils.script_paths("addons")[-1] - if os.path.exists(path_dest): - self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest) - return {'CANCELLED'} + #check to see if the file is in compressed format (.zip) + if zipfile.is_zipfile(pyfile): + try: + file_to_extract = zipfile.ZipFile(pyfile, 'r') - if os.path.exists(path_dest): - self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest) - return {'CANCELLED'} + #extract the file to "addons" + file_to_extract.extractall(path_addons) + + except: + traceback.print_exc() + return {'CANCELLED'} - try: - shutil.copyfile(pyfile, path_dest) - except: - traceback.print_exc() - return {'CANCELLED'} + else: + path_dest = os.path.join(path_addons, os.path.basename(pyfile)) + + if os.path.exists(path_dest): + self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest) + return {'CANCELLED'} + + #if not compressed file just copy into the addon path + try: + shutil.copyfile(pyfile, path_dest) + + except: + traceback.print_exc() + return {'CANCELLED'} # TODO, should not be a warning. # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest) |