def extract_compress (archive, compression, cmd, **kwargs): """Extract a compressed archive.""" cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') outfile = util.get_single_outfile(kwargs['outdir'], archive) cmdlist.extend(['-c', util.shell_quote(archive), '>', util.shell_quote(outfile)]) return (cmdlist, {'shell': True})
def extract_singlefile_standard (archive, compression, cmd, **kwargs): """Standard routine to extract a singlefile archive (like gzip).""" cmdlist = [util.shell_quote(cmd)] if kwargs['verbose']: cmdlist.append('-v') outfile = util.get_single_outfile(kwargs['outdir'], archive) cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>', util.shell_quote(outfile)]) return (cmdlist, {'shell': True})
def extract_lrzip (archive, compression, cmd, **kwargs): """Extract a LRZIP archive.""" # Since extracted files will be placed in the current directory, # the cwd argument has to be the output directory. cmdlist = [cmd, '-d'] if kwargs['verbose']: cmdlist.append('-v') outfile = util.get_single_outfile(kwargs['outdir'], archive) cmdlist.extend(["-o", outfile, os.path.abspath(archive)]) return (cmdlist, {'cwd': kwargs['outdir']})
def extract_bzip2 (archive, compression, cmd, **kwargs): """Extract a BZIP2 archive with the bz2 Python module.""" verbose = kwargs['verbose'] outdir = kwargs['outdir'] # XXX honor outdir if verbose: util.log_info('extracting %s...' % archive) targetname = util.get_single_outfile(kwargs['outdir'], archive) bz2file = bz2.BZ2File(archive) try: targetfile = open(targetname, 'wb') try: data = bz2file.read(READ_SIZE_BYTES) while data: targetfile.write(data) data = bz2file.read(READ_SIZE_BYTES) finally: targetfile.close() finally: bz2file.close() if verbose: util.log_info('... extracted to %s' % targetname) return None