extract zip or tar content to dstdir
192774
def extractall(archive, filename, dstdir):
    
    
    if zipfile.is_zipfile(archive):
        z = zipfile.ZipFile(archive)
        for name in z.namelist():
            targetname = name
            # directories ends with '/' (on Windows as well)
            if targetname.endswith('/'):
                targetname = targetname[:-1]

            # don't include leading "/" from file name if present
            if targetname.startswith(os.path.sep):
                targetname = os.path.join(dstdir, targetname[1:])
            else:
                targetname = os.path.join(dstdir, targetname)                
            targetname = os.path.normpath(targetname)

            # Create all upper directories if necessary.    
            upperdirs = os.path.dirname(targetname)
            if upperdirs and not os.path.exists(upperdirs):
                os.makedirs(upperdirs)

            # directories ends with '/' (on Windows as well)
            if not name.endswith('/'):
                # copy file
                file(targetname, 'wb').write(z.read(name))

    elif tarfile.is_tarfile(archive):
        tar = tarfile.open(archive)
        tar.extractall(path=dstdir)
    else:
        # seems to be a single file, save it
        shutil.copyfile(archive, os.path.join(dstdir, filename))
106689
def write_tree(zipf, src_directory, dst_directory):
    
    if not os.path.exists(src_directory):
        abort('Tree ' + src_directory + ' does not exist.')
    for root, _, files in os.walk(src_directory):
        for filename in files:
            if not filename.endswith(('.py', '.pem')):
                continue
            fullname = os.path.join(root, filename)
            arcname = fullname.replace(src_directory, dst_directory)
            zipf.write(fullname, arcname=arcname)
329845
def list_tar (archive, compression, cmd, verbosity, interactive):
    """"""
    cmdlist = [cmd, '--list']
    add_tar_opts(cmdlist, compression, verbosity)
    cmdlist.extend(["--file", archive])
    return cmdlist
1103659
def compress_delete_outdir(outdir):
    """"""
    # Compress output in .tar.gz file and remove raw output
    tarfn = outdir + ".tar.gz"
    logger.info("\tCompressing output from %s to %s", outdir, tarfn)
    with tarfile.open(tarfn, "w:gz") as fh:
        fh.add(outdir)
    logger.info("\tRemoving output directory %s", outdir)
    shutil.rmtree(outdir)
659445
def unpack(src_dir, dst_dir):
    ''''''
    for dirpath, dirnames, filenames in os.walk(src_dir):
        subdir = os.path.relpath(dirpath, src_dir)
        for f in filenames:
            src = os.path.join(dirpath, f)
            dst = os.path.join(dst_dir, subdir, f)
            os.renames(src, dst)
        for n, d in reversed(list(enumerate(dirnames))):
            src = os.path.join(dirpath, d)
            dst = os.path.join(dst_dir, subdir, d)
            if not os.path.exists(dst):
                # Directory does not exist in destination,
                # rename it and prune it from os.walk list.
                os.renames(src, dst)
                del dirnames[n]
    # Cleanup.
    for dirpath, dirnames, filenames in os.walk(src_dir, topdown=True):
        assert not filenames
        os.rmdir(dirpath)
90237
def extract_shn (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    cmdlist = [util.shell_quote(cmd)]
    outfile = util.get_single_outfile(outdir, archive, extension=".wav")
    cmdlist.extend(['-x', '-', util.shell_quote(outfile), '<',
        util.shell_quote(archive)])
    return (cmdlist, {'shell': True})
827545
def extract_zipfile(archive_name, destpath):
    ""
    archive = zipfile.ZipFile(archive_name)
    archive.extractall(destpath)
3930
def extract_tarfile(archive_name, destpath):
    ""
    archive = tarfile.open(archive_name)
    archive.extractall(destpath)
959053
def unpackfile(filename, destdir):
    """"""
    if filename.endswith(".mar"):
        return unpackmar(filename, destdir)
    elif filename.endswith(".exe"):
        return unpackexe(filename, destdir)
    elif filename.endswith(".tar") or filename.endswith(".tar.gz") \
            or filename.endswith(".tgz"):
        return unpacktar(filename, destdir)
    else:
        raise ValueError("Unknown file type: %s" % filename)
941170
def convertPath(srcpath, dstdir):
    """"""
    bits = srcpath.split("/")
    bits.pop(0)
    # Strip out leading 'unsigned' from paths like unsigned/update/win32/...
    if bits[0] == 'unsigned':
        bits.pop(0)
    return os.path.join(dstdir, *bits)
1160117
def unpacktar(tarfile, destdir):
    
    nullfd = open(os.devnull, "w")
    tarfile = cygpath(os.path.abspath(tarfile))
    log.debug("unpack tar %s into %s", tarfile, destdir)
    try:
        check_call([TAR, '-xzf', tarfile], cwd=destdir,
                   stdout=nullfd, preexec_fn=_noumask)
    except Exception:
        log.exception("Error unpacking tar file %s to %s", tarfile, destdir)
        raise
    nullfd.close()
1241116
def _unpack(self, tar_file, directory):
        

        self.log.info("Unpacking %s tar file to %s directory" %
                      (tar_file, directory))

        with tarfile.open(tar_file, 'r') as tar:
            tar.extractall(path=directory)

        self.log.info("Archive unpacked!")
1238306
def _extract_file(self, tgz, tarinfo, dst_path, buffer_size=10<<20):
    """"""
    src = tgz.extractfile(tarinfo)
    dst = tf_v1.gfile.GFile(dst_path, "wb")
    while 1:
      buf = src.read(buffer_size)
      if not buf:
        break
      dst.write(buf)
      self._log_progress(len(buf))
    dst.close()
    src.close()
992520
def extract_tar (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    try:
        with tarfile.open(archive) as tfile:
            tfile.extractall(path=outdir)
    except Exception as err:
        msg = "error extracting %s: %s" % (archive, err)
        raise util.PatoolError(msg)
    return None
361224
def copy(src, dst):
    
    if os.path.isdir(dst):
        dst = os.path.join(dst, os.path.basename(src))
    copyfile(src, dst)
    copymode(src, dst)
644759
def extract(self, dest_fldr, password=''):
        
        #print('extracting to ' + dest_fldr)
        if self.type == 'ZIP':
            self._extract_zip(dest_fldr, password)
        elif self.type == 'GZ':
            self._extract_gz(dest_fldr, password)
        elif self.type == 'TAR':
            self._extract_tar(dest_fldr, self.fname)
        else:
            raise('Unknown archive file type')
1238477
def extract_alzip (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return [cmd, '-d', outdir, archive]