patch from Andy Braham with some modifications
authorCampbell Barton <ideasman42@gmail.com>
Sat, 27 Feb 2010 22:36:37 +0000 (22:36 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 27 Feb 2010 22:36:37 +0000 (22:36 +0000)
extracts zipfiles when installing add-ons

release/scripts/ui/space_userpref.py

index 0526f1e99d40f595a9478fb638f780121d06e453..bea9f80edec96bb9027cbd6643f2abeb6c0129c1 100644 (file)
@@ -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)