Пример #1
0
def squeeze(test_dir, output_dir, configuration, clean):
    """Simple program that copies test_dir to output_dir, compresseses all
    images it finds in it and outputs efficiency stats."""
    total_time = total_size = total_reduced_size = no_files = 0

    raw_config = process.read_yaml_configuration(configuration)
    config = process.parse_configuration(raw_config)

    click.echo('Making a copy of test files...')
    files = copy_dir(test_dir, output_dir)

    click.echo('Testing...')
    stats_file = os.path.join(output_dir, 'stats.csv')
    with open(stats_file, 'wb') as csvfile:
        csvwriter = csv.writer(csvfile, delimiter=',', quotechar='|',
                               quoting=csv.QUOTE_MINIMAL)

        for filename in get_files(files):
            stats = test_compression(filename, config)
            if stats:  # Skip ignored files
                csvwriter.writerow(stats)

                no_files += 1
                total_time += stats.time
                total_size += stats.orig_size
                total_reduced_size += stats.new_size

    if clean:
        clean_files(files)

    summary = """\

Files: {}
Total size: {}
Reduced size: {}
Reduced by (%): {}
Time spent (seconds): {}
"""
    total_reduced_by = calc_effectiveness(total_size, total_reduced_size)
    click.echo(summary.format(no_files, total_size, total_reduced_size,
                              total_reduced_by, total_time))
Пример #2
0
def test_read_yaml_configuration():
    f = join(TEST_FILES_DIR, 'config.yaml')
    config = diet.read_yaml_configuration(f)
    assert isinstance(config, dict)
Пример #3
0
def diet(file, configuration, check):
    """Simple program that either print config customisations for your
    environment or compresses file FILE."""
    config = process.read_yaml_configuration(configuration)
    process.diet(file, config)
Пример #4
0
def diet(file, configuration, check):
    """Simple program that either print config customisations for your
    environment or compresses file FILE."""
    config = process.read_yaml_configuration(configuration)
    process.diet(file, config)
Пример #5
0
def test_read_yaml_configuration():
    f = join(TEST_FILES_DIR, 'config.yaml')
    config = diet.read_yaml_configuration(f)
    assert isinstance(config, dict)