def end_contents(): self._restore_state(cur_state) if not self.dry_run: create_zipfile(t_temp,z_temp,members=zfmeta[0].infolist()) with open(z_temp,"rb") as f: data = f.read(1024*16) while data: self.outfile.write(data) data = f.read(1024*16) zfmeta[0].close() really_rmtree(workdir)
def _run_create_zipfile(self): """Zip up the final distribution.""" print "zipping up the esky" fullname = self.distribution.get_fullname() platform = get_platform() zfname = os.path.join(self.dist_dir,"%s.%s.zip"%(fullname,platform,)) if hasattr(self.freezer_module,"zipit"): self.freezer_module.zipit(self,self.bootstrap_dir,zfname) else: create_zipfile(self.bootstrap_dir,zfname,compress=True) really_rmtree(self.bootstrap_dir)
def _run_create_zipfile(self): """Zip up the final distribution.""" print "zipping up the esky" fullname = self.distribution.get_fullname() platform = get_platform() zfname = os.path.join(self.dist_dir, "%s.%s.zip" % (fullname, platform, )) if hasattr(self.freezer_module, "zipit"): self.freezer_module.zipit(self, self.bootstrap_dir, zfname) else: create_zipfile(self.bootstrap_dir, zfname, compress=True) # Only remove bootstrap dir if option is passed if (self.rm_freeze_dir_after_zipping and self.rm_freeze_dir_after_zipping != 'False'): really_rmtree(self.bootstrap_dir)
def zipit(dist,bsdir,zfname): """Create the final zipfile of the esky. We customize this process for py2app, so that the zipfile contains a toplevel "<appname>.app" directory. This allows users to just extract the zipfile and have a proper application all set up and working. """ def get_arcname(fpath): return os.path.join(dist.distribution.get_name()+".app",fpath) return create_zipfile(bsdir,zfname,get_arcname,compress=True)
def _run_create_zipfile(self): """Zip up the final distribution.""" if self.compress: fullname = self.distribution.get_fullname() platform = get_platform() zfname = os.path.join(self.dist_dir,"%s.%s.zip"%(fullname,platform,)) if hasattr(self.freezer_module,"zipit"): self.freezer_module.zipit(self,self.bootstrap_dir,zfname) else: if self.compress == 'zip': print "zipping up the esky with compression" create_zipfile(self.bootstrap_dir,zfname,compress=True) really_rmtree(self.bootstrap_dir) elif self.compress == 'ZIP': print "zipping up the esky without compression" create_zipfile(self.bootstrap_dir,zfname,compress=False) really_rmtree(self.bootstrap_dir) else: print("To zip the esky use compress or c set to ZIP or zip")
def main(args): """Command-line diffing and patching for esky.""" parser = optparse.OptionParser() parser.add_option("-z","--zipped",action="store_true",dest="zipped", help="work with zipped source/target dirs") parser.add_option("-Z","--deep-zipped",action="store_true", dest="deep_zipped", help="work with deep zipped source/target dirs") parser.add_option("","--diff-window",dest="diff_window",metavar="N", help="set the window size for diffing files") parser.add_option("","--dry-run",dest="dry_run",action="store_true", help="print commands instead of executing them") (opts,args) = parser.parse_args(args) if opts.deep_zipped: opts.zipped = True if opts.zipped: workdir = tempfile.mkdtemp() if opts.diff_window: scale = 1 if opts.diff_window[-1].lower() == "k": scale = 1024 opts.diff_window = opts.diff_window[:-1] elif opts.diff_window[-1].lower() == "m": scale = 1024 * 1024 opts.diff_window = opts.diff_window[:-1] elif opts.diff_window[-1].lower() == "g": scale = 1024 * 1024 * 1024 opts.diff_window = opts.diff_window[:-1] opts.diff_window = int(float(opts.diff_window)*scale) stream = None try: cmd = args[0] if cmd == "diff": # Generate a diff between two files/directories. # If --zipped is specified, the source and/or target is unzipped # to a temporary directory before processing. source = args[1] target = args[2] if len(args) > 3: stream = open(args[3],"wb") else: stream = sys.stdout if opts.zipped: if os.path.isfile(source): source_zip = source source = os.path.join(workdir,"source") if opts.deep_zipped: deep_extract_zipfile(source_zip,source) else: extract_zipfile(source_zip,source) if os.path.isfile(target): target_zip = target target = os.path.join(workdir,"target") if opts.deep_zipped: deep_extract_zipfile(target_zip,target) else: extract_zipfile(target_zip,target) write_patch(source,target,stream,diff_window_size=opts.diff_window) elif cmd == "patch": # Patch a file or directory. # If --zipped is specified, the target is unzipped to a temporary # directory before processing, then overwritten with a zipfile # containing the new directory contents. target = args[1] if len(args) > 2: stream = open(args[2],"rb") else: stream = sys.stdin target_zip = None if opts.zipped: if os.path.isfile(target): target_zip = target target = os.path.join(workdir,"target") if opts.deep_zipped: deep_extract_zipfile(target_zip,target) else: extract_zipfile(target_zip,target) apply_patch(target,stream,dry_run=opts.dry_run) if opts.zipped and target_zip is not None: target_dir = os.path.dirname(target_zip) (fd,target_temp) = tempfile.mkstemp(dir=target_dir) os.close(fd) if opts.deep_zipped: prefix = zipfile_common_prefix_dir(target_zip) def name_filter(nm): return prefix + nm create_zipfile(target,target_temp,name_filter) else: create_zipfile(target,target_temp) if sys.platform == "win32": os.unlink(target_zip) time.sleep(0.01) really_rename(target_temp,target_zip) else: raise ValueError("invalid command: " + cmd) finally: if stream is not None: if stream not in (sys.stdin,sys.stdout,): stream.close() if opts.zipped: really_rmtree(workdir)