Skip to content

Instantly share code, notes, and snippets.

@bohdon
Created February 13, 2019 04:41
Show Gist options
  • Select an option

  • Save bohdon/f2e91ea8c78bc44ee10dcbe27bc37168 to your computer and use it in GitHub Desktop.

Select an option

Save bohdon/f2e91ea8c78bc44ee10dcbe27bc37168 to your computer and use it in GitHub Desktop.
Sync P4 files below size limit
import os
import click
from P4 import P4
@click.command()
@click.argument('path')
@click.option('-s', '--max-size', default=5, help='maximum size of the file, in MB')
def sync_by_size(path, max_size):
p4 = P4()
p4.connect()
max_size_bytes = max_size * 1048576
click.echo(p4)
click.echo('skipping files above {}MB'.format(max_size))
sizes = p4.run_sizes(path)
valid_files = [f['depotFile']
for f in sizes if int(f['fileSize']) <= max_size_bytes]
skip_count = len(sizes) - len(valid_files)
click.echo('skipping {} file(s) above size limit'.format(skip_count))
result = p4.run_sync(valid_files)
click.echo(result)
if __name__ == '__main__':
sync_by_size()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment