コード例 #1
0
def write_set(contents_set, filepath, compressor='bzip2', absolute_paths=False,
              parallelize=False):
    if compressor == 'bz2':
        compressor = 'bzip2'

    tar_handle = None
    handle = compression.compress_handle(compressor, filepath,
        parallelize=parallelize)
    try:
        tar_handle = tarfile.TarFile(name=filepath, fileobj=handle, mode='w')
        add_contents_to_tarfile(contents_set, tar_handle)
    finally:
        if tar_handle is not None:
            tar_handle.close()
        handle.close()
コード例 #2
0
def generate_contents(filepath, compressor="bz2", parallelize=True):
    """
    generate a contentset from a tarball

    :param filepath: string path to location on disk
    :param compressor: defaults to bz2; decompressor to use, see
        :obj:`known_compressors` for list of valid compressors
    """

    if compressor == 'bz2':
        compressor = 'bzip2'

    tar_handle = None
    handle = compression.decompress_handle(compressor, filepath,
        parallelize=parallelize)

    try:
        tar_handle = tarfile.TarFile(name=filepath, fileobj=handle, mode='r')
    except tarfile.ReadError as e:
        if not e.message.endswith("empty header"):
            raise
        tar_handle = []
    return convert_archive(tar_handle)