Create TAR file.
341672
def _create_tar(self, name):
        """"""
        fileobj = utils.create_spooled_temporary_file()
        mode = 'w:gz' if self.compress else 'w'
        tar_file = tarfile.open(name=name, fileobj=fileobj, mode=mode)
        for media_filename in self._explore_storage():
            tarinfo = tarfile.TarInfo(media_filename)
            media_file = self.media_storage.open(media_filename)
            tarinfo.size = len(media_file)
            tar_file.addfile(tarinfo, media_file)
        # Close the TAR for writing
        tar_file.close()
        return fileobj
141241
def create_model_tar(matrices, tarname="model-cuda-converted.tar"):
    
    # Write layers
    filenames = []
    for layer in range(len(matrices)):
        if matrices[layer]['name'] == 'W':
            weights = matrices[layer]['storage']
            weights_file = h5py.File('W%i.hdf5' % (layer / 2), 'w')
            weights_file.create_dataset(weights_file.id.name, data=weights)
            weights_file.close()
            filenames.append('W%i.hdf5' % (layer / 2))
        elif matrices[layer]['name'] == 'b':
            b = matrices[layer]['storage']
            bfile = h5py.File('b%i.hdf5' % (layer / 2), 'w')
            bfile.create_dataset(bfile.id.name, data=b)
            bfile.close()
            filenames.append('b%i.hdf5' % (layer / 2))

        # activation = a['layers'][layer]['_props']['activation']
        # activation = activation.replace('sigmoid', 'Sigmoid')
        # activation = activation.replace('softmax', 'Softmax')
        # layers.append({'W': {'size': list(W.shape),
        #                      'filename': 'W%i.hdf5' % layer},
        #                'b': {'size': list(b.shape),
        #                      'filename': 'b%i.hdf5' % layer},
        #                'activation': activation})
    with tarfile.open(tarname, "w:") as tar:
        for name in filenames:
            tar.add(name)

    # Remove temporary files which are now in tar file
    for filename in filenames:
        os.remove(filename)
107798
def tar_to_bigfile(self, fname, outfile):
        """"""
        fnames = []
        tmpdir = mkdtemp()
        
        # Extract files to temporary directory
        with tarfile.open(fname) as tar:
            tar.extractall(path=tmpdir)
        for root, _, files in os.walk(tmpdir):
            fnames += [os.path.join(root, fname) for fname in files]
        
        # Concatenate
        with open(outfile, "w") as out:
            for infile in fnames:
                for line in open(infile):
                    out.write(line)
                os.unlink(infile)
        
        # Remove temp dir
        shutil.rmtree(tmpdir)
569545
def create_zip(archive, compression, cmd, verbosity, interactive, filenames):
    """"""
    try:
        with zipfile.ZipFile(archive, 'w') as zfile:
            for filename in filenames:
                if os.path.isdir(filename):
                    write_directory(zfile, filename)
                else:
                    zfile.write(filename)
    except Exception as err:
        msg = "error creating %s: %s" % (archive, err)
        raise util.PatoolError(msg)
    return None
835417
def create_tar_file(self, full_archive=False):
        
        tar_file_name = os.path.join(self.archive_tmp_dir, self.archive_name)
        ext = "" if self.compressor == "none" else ".%s" % self.compressor
        tar_file_name = tar_file_name + ".tar" + ext
        logger.debug("Tar File: " + tar_file_name)
        subprocess.call(shlex.split("tar c%sfS %s -C %s ." % (
            self.get_compression_flag(self.compressor),
            tar_file_name,
            # for the docker "uber archive,"use archive_dir
            #   rather than tmp_dir for all the files we tar,
            #   because all the individual archives are in there
            self.tmp_dir if not full_archive else self.archive_dir)),
            stderr=subprocess.PIPE)
        self.delete_archive_dir()
        logger.debug("Tar File Size: %s", str(os.path.getsize(tar_file_name)))
        return tar_file_name
794995
def _create(archive, compression, cmd, format, verbosity, filenames):
    """"""
    if len(filenames) > 1:
        raise util.PatoolError('multi-file compression not supported in Python lzma')
    try:
        with lzma.LZMAFile(archive, mode='wb', **_get_lzma_options(format, preset=9)) as lzmafile:
            filename = filenames[0]
            with open(filename, 'rb') as srcfile:
                data = srcfile.read(READ_SIZE_BYTES)
                while data:
                    lzmafile.write(data)
                    data = srcfile.read(READ_SIZE_BYTES)
    except Exception as err:
        msg = "error creating %s: %s" % (archive, err)
        raise util.PatoolError(msg)
    return None
1286064
def make_tarball(tarball_fname,directory,cwd=None):
    ""
    if tarball_fname.endswith('.gz'): opts = 'czf'
    else: opts = 'cf'
    args = ['/bin/tar',opts,tarball_fname,directory]
    process_command(args, cwd=cwd)
785195
def list_tar (archive, compression, cmd, verbosity, interactive):
    """"""
    try:
        with tarfile.open(archive) as tfile:
            tfile.list(verbose=verbosity>1)
    except Exception as err:
        msg = "error listing %s: %s" % (archive, err)
        raise util.PatoolError(msg)
    return None
1191350
def setup(self):
        
        r = self.call_ext_prog(self.get_option("script"))
        if r['status'] == 0:
            tarfile = ""
            for line in r['output']:
                line = line.strip()
                tarfile = self.do_regex_find_all(r"ftp (.*tar.gz)", line)
            if len(tarfile) == 1:
                self.add_copy_spec(tarfile[0])
1067828
def _create_file(self, filename):
        """"""
        file_descriptor = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
        return os.fdopen(file_descriptor, 'w')
179235
def create_tar (archive, compression, cmd, verbosity, interactive, filenames):
    """"""
    cmdlist = [cmd, '-c']
    add_star_opts(cmdlist, compression, verbosity)
    cmdlist.append("file=%s" % archive)
    cmdlist.extend(filenames)
    return cmdlist
1007403
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
        """"""
        cls = StreamReader if 'r' in mode else StreamWriter
        return cls(sock, mode, bufsize)
197274
def create_arj (archive, compression, cmd, verbosity, interactive, filenames):
    """"""
    cmdlist = [cmd, 'a', '-r']
    if not interactive:
        cmdlist.append('-y')
    cmdlist.append(archive)
    cmdlist.extend(filenames)
    return cmdlist
1164175
def _tar_and_copy(src_dir, target_dir):
  """"""
  src_dir = src_dir.rstrip("/")
  target_dir = target_dir.rstrip("/")
  tmp_dir = tempfile.gettempdir().rstrip("/")
  src_base = os.path.basename(src_dir)
  shell_run(
      "tar --exclude=.git -zcf {tmp_dir}/{src_base}.tar.gz -C {src_dir} .",
      src_dir=src_dir,
      src_base=src_base,
      tmp_dir=tmp_dir)
  final_destination = "%s/%s.tar.gz" % (target_dir, src_base)
  shell_run(
      ("gsutil cp {tmp_dir}/{src_base}.tar.gz "
       "{final_destination}"),
      tmp_dir=tmp_dir,
      src_base=src_base,
      final_destination=final_destination)
  return final_destination
951451
def create_tarfile(files: List[str], tar_path: str) -> None:
    """"""
    with tarfile.open(tar_path, "w:gz") as tar:
        for f in files:
            tar.add(f)
506425
def tar_dir(tarfile, srcdir):
    
    files = os.listdir(srcdir)
    packtar(tarfile, files, srcdir)
329845
def list_tar (archive, compression, cmd, verbosity, interactive):
    """"""
    cmdlist = [cmd, '--list']
    add_tar_opts(cmdlist, compression, verbosity)
    cmdlist.extend(["--file", archive])
    return cmdlist