From 03d21a79df10c2e12d9e0faeab85a2589fbc11fb Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 23 Apr 2020 10:07:03 +0100 Subject: [PATCH 1/3] Option to not show progressbar. --- scripts/s3_media_upload | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) 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) From 52f2a5bbef41fc39adbea9546b8ff14adaa06cc8 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 29 Oct 2020 14:39:14 +0000 Subject: [PATCH 2/3] Make writes to progress be in global scope. --- scripts/s3_media_upload | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/s3_media_upload b/scripts/s3_media_upload index 3a86587..7fcdb4a 100644 --- a/scripts/s3_media_upload +++ b/scripts/s3_media_upload @@ -421,6 +421,7 @@ def main(): args = parser.parse_args() if args.no_progress: + global progress progress=False if args.cmd == "write": From 3c8ea6076f8bcb6fb25862408c9a7a853ce79f92 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 18 Jan 2021 10:08:42 +0000 Subject: [PATCH 3/3] Fix up formatting Co-authored-by: Patrick Cloke --- scripts/s3_media_upload | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/s3_media_upload b/scripts/s3_media_upload index 7fcdb4a..255dc9a 100644 --- a/scripts/s3_media_upload +++ b/scripts/s3_media_upload @@ -27,7 +27,7 @@ SCHEMA = """ CREATE INDEX IF NOT EXISTS deleted_idx ON media(known_deleted); """ -progress=True +progress = True def parse_duration(string): """Parse a string into a duration supports suffix of d, m or y. @@ -422,7 +422,7 @@ def main(): args = parser.parse_args() if args.no_progress: global progress - progress=False + progress = False if args.cmd == "write": sqlite_conn = get_sqlite_conn(parser)