-
-
Save eharkins/408a63111bc624ae139b8941ab2e1b1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import argparse | |
import subprocess | |
def parse_args(): | |
parser = argparse.ArgumentParser( | |
description="upload and verify successful upload of a gzip file to economy file storage" | |
) | |
parser.add_argument("src", type=str, help="path to local file to upload.") | |
parser.add_argument("targ", type=str, help="destination path on economy file storage.") | |
return parser.parse_args() | |
def run_swc(action, src, targ): | |
subprocess.check_call(["swc", action, src, targ]) | |
def upload_and_verify(src, targ): | |
run_swc("upload", src, targ) | |
# compare md5sums | |
run_swc("hash", src, targ) | |
# redownload locally to the same name as the destination filename | |
redownload_dir = os.path.join(os.getcwd(), "verified_uploads") | |
if not os.path.exists(redownload_dir): | |
os.makedirs(redownload_dir) | |
print("redownloading {} to {} and checking that we can unzip".format(targ, redownload_dir)) | |
run_swc("download", targ, redownload_dir) | |
redownloaded_path = os.path.join(redownload_dir, os.path.split(targ)[-1]) | |
try: | |
subprocess.check_call(["gzip", "-t", redownloaded_path]) | |
except Exception, e: | |
print("Upload failed: cannot unzip after redownloading file. This means it is not a valid gzip format file.") | |
raise | |
def main(): | |
args = parse_args() | |
upload_and_verify(args.src, args.targ) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment