def execute(self, context): blendpath = bpy.data.filepath if not blendpath: msg = 'you must save the .blend first before we can compress it' self.report({'INFO'}, msg) return {'CANCELLED'} blend_archive_path, blendname = propose_archive_filepath( blendpath, extension=self.archive_ext) context.window_manager.clipboard = blend_archive_path if self.archive_ext == 'zip': with zipfile.ZipFile(blend_archive_path, 'w', zipfile.ZIP_DEFLATED) as myzip: myzip.write(blendpath, blendname) self.complete_msg(blend_archive_path) show_selected_in_OSfilebrowsesr(file_path=blend_archive_path) return {'FINISHED'} elif self.archive_ext == 'gz': import gzip import shutil with open(blendpath, 'rb') as f_in: with gzip.open(blend_archive_path, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) self.complete_msg(blend_archive_path) show_selected_in_OSfilebrowsesr(file_path=blend_archive_path) return {'FINISHED'} return {'CANCELLED'}
def execute(self, context): blendpath = bpy.data.filepath if not blendpath: msg = 'you must save the .blend first before we can compress it' self.report({'INFO'}, msg) return {'CANCELLED'} blend_archive_path, blendname = propose_archive_filepath(blendpath, extension=self.archive_ext) context.window_manager.clipboard = blend_archive_path if self.archive_ext == 'zip': with zipfile.ZipFile(blend_archive_path, 'w', zipfile.ZIP_DEFLATED) as myzip: myzip.write(blendpath, blendname) self.complete_msg(blend_archive_path) show_selected_in_OSfilebrowsesr(file_path=blend_archive_path) return {'FINISHED'} elif self.archive_ext == 'gz': import gzip import shutil with open(blendpath, 'rb') as f_in: with gzip.open(blend_archive_path, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) self.complete_msg(blend_archive_path) show_selected_in_OSfilebrowsesr(file_path=blend_archive_path) return {'FINISHED'} return {'CANCELLED'}