Merge pull request #48 from matrix-org/michaelkaye/allow_option_not_to_use_upload

Option to not show progressbar.
This commit is contained in:
Erik Johnston 2021-01-18 10:36:31 +00:00 committed by GitHub
commit 887ee24d76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(
@ -412,6 +426,9 @@ def main():
)
args = parser.parse_args()
if args.no_progress:
global progress
progress = False
if args.cmd == "write":
sqlite_conn = get_sqlite_conn(parser)