From 79a5362b44070d02589b99b5046943ce4e65cc77 Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort Date: Wed, 9 Mar 2022 16:09:52 +0100 Subject: [PATCH] WIP: make it so that doing : python download_data.py is all you need from a user standpoint --- download_data.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/download_data.py b/download_data.py index b124d08..da2f784 100644 --- a/download_data.py +++ b/download_data.py @@ -7,6 +7,9 @@ import argparse import tempfile import tarfile +import getpass +import subprocess +import webbrowser data = { @@ -48,7 +51,7 @@ def data_fetch(check_hash=True): ------- None """ - wget.download(data["url"]) + # wget.download(data["url"]) filename = os.path.basename(data["url"]) if check_hash: @@ -57,9 +60,31 @@ def data_fetch(check_hash=True): if check_hash_correct(filename, data["encrypted_hash"]): print("Data verified to be correct.") else: - print( + raise ValueError( "There is something wrong with the data. Verify that the expected files are present." ) + + print("Decrypting archive.") + # Decrypt the data. + retcode = subprocess.call( + ['openssl', 'aes-256-cbc', '-md', 'sha256', + '-d', '-a', '-in', + 'ATLAS_R2.0_encrypted.tar.gz', '-out', 'ATLAS_R2.0.tar.gz', + '-pass', f'pass:{getpass.getpass("Enter password:")}'] + ) + + if retcode != 0: # decrypt failed + url_form = "https://docs.google.com/forms/d/e/1FAIpQLSclH8padHr9zwdQVx9YY_yeM_4OqD1OQFvYcYpAQKaqC6Vscg/viewform" + print("Decrypting failed due to missing openssl command or invalid password. Opening form" + " for you to get this password.") + webbrowser.open_new_tab(url_form) + return + + print("Extracting archive.") + tar = tarfile.open(filename.replace("_encrypted", ""), "r:gz") + tar.extractall("./data") + tar.close() + print("Done.") return