patch from Andy Braham with some modifications

extracts zipfiles when installing add-ons
This commit is contained in:
Campbell Barton 2010-02-27 22:36:37 +00:00
parent 769eb45124
commit 7ab601747a

@ -1471,24 +1471,37 @@ class WM_OT_addon_install(bpy.types.Operator):
def execute(self, context): def execute(self, context):
import traceback import traceback
import zipfile
pyfile = self.properties.path pyfile = self.properties.path
paths = bpy.utils.script_paths("addons") path_addons = bpy.utils.script_paths("addons")[-1]
path_dest = os.path.join(paths[-1], os.path.basename(pyfile))
if os.path.exists(path_dest): #check to see if the file is in compressed format (.zip)
self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest) if zipfile.is_zipfile(pyfile):
return {'CANCELLED'} try:
file_to_extract = zipfile.ZipFile(pyfile, 'r')
if os.path.exists(path_dest): #extract the file to "addons"
self.report({'WARNING'}, "File already installed to '%s'\n" % path_dest) file_to_extract.extractall(path_addons)
return {'CANCELLED'}
except:
traceback.print_exc()
return {'CANCELLED'}
try: else:
shutil.copyfile(pyfile, path_dest) path_dest = os.path.join(path_addons, os.path.basename(pyfile))
except:
traceback.print_exc() if os.path.exists(path_dest):
return {'CANCELLED'} 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. # TODO, should not be a warning.
# self.report({'WARNING'}, "File installed to '%s'\n" % path_dest) # self.report({'WARNING'}, "File installed to '%s'\n" % path_dest)