Exemplo n.º 1
0
def process_files(list_files, source_dir, target_dir, overwrite, alg, zlevel,
                  blocksize, force, legacy, ignore_attributes):
    osizesum = 0
    csizesum = 0
    for f in list_files:
        target_file = target_dir / f.relative_to(source_dir)

        if f.is_symlink():
            try:
                f.resolve().relative_to(source_dir.resolve())
            except ValueError:
                # The link is outside dir. Just follow the normal process and treat it as file
                pass
            else:
                # The symlink is inside the source dir. Create its correspondent symlink in target_dir
                target_file.symlink_to(os.readlink(f))
                continue
        elif f.is_dir():
            # Is a empty dir
            target_file.mkdir(parents=True)
            if not ignore_attributes:
                # Use fake file to get correct dir path
                clone_dir_attributes((f / 'fake.txt').parents,
                                     (target_file / 'fake.txt').parents)

            continue

        osizesum += f.stat().st_size

        if target_file.exists() and not overwrite:
            csizesum += target_file.stat().st_size
            print(f"{target_file}: SKIPED")
            continue

        compress_file(f,
                      target_file,
                      blocksize=blocksize,
                      algorithm=alg,
                      zlevel=zlevel,
                      force=force,
                      legacy=legacy)

        csizesum += target_file.stat().st_size

        print(
            f"{target_file}: {sizeof_fmt(f.stat().st_size)} -> {sizeof_fmt(target_file.stat().st_size)}"
        )

    print(f"Total input size : {sizeof_fmt(osizesum)}")
    print(f"Total output size: {sizeof_fmt(csizesum)}")
Exemplo n.º 2
0
def test_full(input_file_full, output_file, legacy):

    ratio = compress_file(input_file_full, output_file, legacy=legacy)

    with pytest.raises(NotCompressedFile):
        FileObject(output_file)

    assert (ratio == 1)

    ratio = compress_file(input_file_full,
                          output_file,
                          force=True,
                          legacy=legacy)

    assert (ratio > 1)

    extracted_file = (output_file.parent / 'result_extracted')
    uncompress_file(output_file, extracted_file)

    assert (get_md5(input_file_full) == get_md5(extracted_file))
Exemplo n.º 3
0
 def call_compress():
     """
     docstring
     """
     return compress_file(input_file,
                          output_file,
                          blocksize=2**blocksize,
                          algorithm=alg,
                          zlevel=2,
                          force=force,
                          legacy=legacy,
                          copy_attributes=copy_attributes)
Exemplo n.º 4
0
def test_holes(input_file_holes, output_file, legacy):
    ratio = compress_file(input_file_holes, output_file, legacy=legacy)

    print('xd')

    assert (ratio < 0.3)

    extracted_file = (output_file.parent / 'result_extracted')
    uncompress_file(output_file, extracted_file)

    assert (get_md5(input_file_holes) == get_md5(extracted_file))

    fobj = FileObject(output_file)
Exemplo n.º 5
0
def test_empty(input_file_empty, output_file):
    compress_file(input_file_empty, output_file)

    assert (output_file.stat().st_size == 0)