From 0af3f1a4950e051b3a079cc75cb35b6b26e795b4 Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Tue, 20 Aug 2024 09:50:19 -0700 Subject: [PATCH 1/3] Added extra logging for tests --- main.py | 39 ++++++++++++++++++--------------------- src/scanner.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/main.py b/main.py index a261f19..8dd9116 100644 --- a/main.py +++ b/main.py @@ -10,27 +10,24 @@ def cli_entrypoint(args): - try: - # using input_file means this is probably running as a script and extra printing wouldn't be appreciated - should_print = args.input_directory or args.server - config = command_log_wrapper("Reading config file:", should_print, lambda: Config().load(args.config_file)) - - if config.inject_torrents: - injector = command_log_wrapper("Connecting to torrent client:", should_print, lambda: Injection(config).setup()) - else: - injector = None - - red_api, ops_api = command_log_wrapper("Verifying API keys:", should_print, lambda: __verify_api_keys(config)) - - if args.server: - run_webserver(args.input_directory, args.output_directory, red_api, ops_api, injector, port=config.server_port) - elif args.input_file: - print(scan_torrent_file(args.input_file, args.output_directory, red_api, ops_api, injector)) - elif args.input_directory: - print(scan_torrent_directory(args.input_directory, args.output_directory, red_api, ops_api, injector)) - except Exception as e: - print(f"{Fore.RED}{str(e)}{Fore.RESET}") - exit(1) + # using input_file means this is probably running as a script and extra printing wouldn't be appreciated + should_print = args.input_directory or args.server + config = command_log_wrapper("Reading config file:", should_print, lambda: Config().load(args.config_file)) + + if config.inject_torrents: + injector = command_log_wrapper("Connecting to torrent client:", should_print, lambda: Injection(config).setup()) + else: + injector = None + + # red_api, ops_api = command_log_wrapper("Verifying API keys:", should_print, lambda: __verify_api_keys(config)) + + if args.server: + run_webserver(args.input_directory, args.output_directory, red_api, ops_api, injector, port=config.server_port) + elif args.input_file: + print(scan_torrent_file(args.input_file, args.output_directory, red_api, ops_api, injector)) + elif args.input_directory: + print(scan_torrent_directory(args.input_directory, args.output_directory, None, None, injector)) + def __verify_api_keys(config): diff --git a/src/scanner.py b/src/scanner.py index 5cfefd4..afc41ce 100644 --- a/src/scanner.py +++ b/src/scanner.py @@ -83,13 +83,29 @@ def scan_torrent_directory( `FileNotFoundError`: if the input directory does not exist. """ + print(f"assert_path_exists called with {input_directory}") input_directory = assert_path_exists(input_directory) + print(f"assert_path_exists returned {input_directory}") + + print(f"mkdir_p called with {output_directory}") output_directory = mkdir_p(output_directory) + print(f"mkdir_p returned {output_directory}") + print(f"list_files_of_extension called with {input_directory}, '.torrent'") input_torrents = list_files_of_extension(input_directory, ".torrent") + print(f"list_files_of_extension returned {len(input_torrents)} torrents") + + print(f"list_files_of_extension called with {output_directory}, '.torrent'") output_torrents = list_files_of_extension(output_directory, ".torrent") + print(f"list_files_of_extension returned {len(output_torrents)} torrents") + + print("__collect_infohashes_from_files called") input_infohashes = __collect_infohashes_from_files(input_torrents) + print(f"__collect_infohashes_from_files returned {len(input_infohashes)} infohashes") + + print("__collect_infohashes_from_files called") output_infohashes = __collect_infohashes_from_files(output_torrents) + print(f"__collect_infohashes_from_files returned {len(output_infohashes)} infohashes") p = Progress(len(input_torrents)) From 24c798fd90813af7a88bc4ef6bcdebf610300bab Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Tue, 20 Aug 2024 10:48:19 -0700 Subject: [PATCH 2/3] oops --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 8dd9116..b5bc6ba 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ def cli_entrypoint(args): else: injector = None - # red_api, ops_api = command_log_wrapper("Verifying API keys:", should_print, lambda: __verify_api_keys(config)) + red_api, ops_api = command_log_wrapper("Verifying API keys:", should_print, lambda: __verify_api_keys(config)) if args.server: run_webserver(args.input_directory, args.output_directory, red_api, ops_api, injector, port=config.server_port) From 234f8871bdc5ed6681e1b7688dc32109a911bacb Mon Sep 17 00:00:00 2001 From: moleculekayak Date: Tue, 20 Aug 2024 14:44:47 -0700 Subject: [PATCH 3/3] Added logging to determine the exact file --- src/scanner.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/scanner.py b/src/scanner.py index afc41ce..8d5fe0e 100644 --- a/src/scanner.py +++ b/src/scanner.py @@ -163,14 +163,19 @@ def scan_torrent_directory( def __collect_infohashes_from_files(files: list[str]) -> dict: infohash_dict = {} - + counter = 0 for filepath in files: + counter += 1 try: torrent_data = get_bencoded_data(filepath) if torrent_data: - infohash = calculate_infohash(torrent_data) - infohash_dict[infohash] = filepath + try: + infohash = calculate_infohash(torrent_data) + infohash_dict[infohash] = filepath + except KeyError as e: + print(f'KeyError: no "info" key in {filepath} (processed {counter} files)') + raise e except UnicodeDecodeError: continue