diff --git a/scripts/s3_media_upload b/scripts/s3_media_upload index cddfb41..3a86587 100644 --- a/scripts/s3_media_upload +++ b/scripts/s3_media_upload @@ -10,6 +10,7 @@ import humanize import psycopg2 import tqdm import yaml +import sys # Schema for our sqlite database cache SCHEMA = """ @@ -26,6 +27,7 @@ SCHEMA = """ CREATE INDEX IF NOT EXISTS deleted_idx ON media(known_deleted); """ +progress=True def parse_duration(string): """Parse a string into a duration supports suffix of d, m or y. @@ -108,11 +110,17 @@ def run_check_delete(sqlite_conn, base_path): """Entry point for check-deleted command """ deleted = [] - for origin, media_id, filesystem_id, m_type in tqdm.tqdm( - get_not_deleted(sqlite_conn), - unit="files", - total=get_not_deleted_count(sqlite_conn), - ): + if progress: + it = tqdm.tqdm( + get_not_deleted(sqlite_conn), + unit="files", + total=get_not_deleted_count(sqlite_conn) + ) + else: + it = get_not_deleted(sqlite_conn) + print("Checking on ", get_not_deleted_count(sqlite_conn), " undeleted files") + + for origin, media_id, filesystem_id, m_type in it: if m_type == "local": file_path = os.path.join( base_path, @@ -246,7 +254,12 @@ def run_upload( deleted_bytes = 0 # This is a progress bar - it = tqdm.tqdm(get_not_deleted(sqlite_conn), unit="files", total=total) + if progress: + it = tqdm.tqdm(get_not_deleted(sqlite_conn), unit="files", total=total) + else: + print("Uploading ", total, " files") + it = get_not_deleted(sqlite_conn) + for origin, media_id, filesystem_id, m_type in it: rel_file_path = to_path(origin, filesystem_id, m_type) @@ -327,6 +340,7 @@ def get_postgres_conn(parser): def main(): parser = argparse.ArgumentParser(prog="s3_media_upload") + parser.add_argument("--no-progress", help="do not show progress bars", action="store_true", dest="no_progress") subparsers = parser.add_subparsers(help="command to run", dest="cmd") update_db_parser = subparsers.add_parser( @@ -406,6 +420,8 @@ def main(): ) args = parser.parse_args() + if args.no_progress: + progress=False if args.cmd == "write": sqlite_conn = get_sqlite_conn(parser)