From 0cc89e7755512242784fc4ed5a8c0c64d6bf689e Mon Sep 17 00:00:00 2001 From: Nikita Skakun Date: Thu, 30 Mar 2023 20:06:12 -0700 Subject: [PATCH] Checksum code now activated by --check flag. --- download-model.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/download-model.py b/download-model.py index 52cdae81..b2788a60 100644 --- a/download-model.py +++ b/download-model.py @@ -26,6 +26,7 @@ parser.add_argument('--threads', type=int, default=1, help='Number of files to d parser.add_argument('--text-only', action='store_true', help='Only download text files (txt/json).') parser.add_argument('--output', type=str, default=None, help='The folder where the model should be saved.') parser.add_argument('--clean', action='store_true', help='Does not resume the previous download.') +parser.add_argument('--check', action='store_true', help='Validates the checksums of model files.') args = parser.parse_args() def get_file(url, output_folder): @@ -215,17 +216,18 @@ if __name__ == '__main__': print(f"Downloading the model to {output_folder}") download_files(links, output_folder, args.threads) - # Validate the checksums - validated = True - for i in range(len(sha256)): - with open(output_folder / sha256[i][0], "rb") as f: - bytes = f.read() - file_hash = hashlib.sha256(bytes).hexdigest() - if file_hash != sha256[i][1]: - print(f'[!] Checksum for {sha256[i][0]} failed!') - validated = False - - if validated: - print('[+] Validated checksums of all model files!') - else: - print('[-] Rerun the download-model.py with --clean flag') \ No newline at end of file + if args.check: + # Validate the checksums + validated = True + for i in range(len(sha256)): + with open(output_folder / sha256[i][0], "rb") as f: + bytes = f.read() + file_hash = hashlib.sha256(bytes).hexdigest() + if file_hash != sha256[i][1]: + print(f'[!] Checksum for {sha256[i][0]} failed!') + validated = False + + if validated: + print('[+] Validated checksums of all model files!') + else: + print('[-] Rerun the download-model.py with --clean flag') \ No newline at end of file