Created
November 2, 2019 17:07
-
-
Save vsoch/84886ef6469bedeeb9a79a4eb7aec0d1 to your computer and use it in GitHub Desktop.
Provides a wrapper script to download a Snakemake Blob, and then extract to a location. This should be moved to be packaged alongside snakemake
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 argparse | |
import datetime | |
from google.cloud import storage | |
def download_blob(bucket_name, source_blob_name, destination_file_name): | |
"""Downloads a blob from the bucket.""" | |
storage_client = storage.Client() | |
bucket = storage_client.get_bucket(bucket_name) | |
blob = bucket.blob(source_blob_name) | |
blob.download_to_filename(destination_file_name) | |
print('Blob {} downloaded to {}.'.format( | |
source_blob_name, | |
destination_file_name)) | |
def blob_commands(args): | |
if args.command == 'download': | |
download_blob( | |
args.bucket_name, | |
args.source_blob_name, | |
args.destination_file_name) | |
def main(): | |
parser = argparse.ArgumentParser( | |
formatter_class=argparse.RawDescriptionHelpFormatter) | |
subparsers = parser.add_subparsers(dest='command') | |
download_parser = subparsers.add_parser( | |
'download', help=download_blob.__doc__) | |
download_parser.add_argument( | |
'bucket_name', help='Your cloud storage bucket.') | |
download_parser.add_argument('source_blob_name') | |
download_parser.add_argument('destination_file_name') | |
args = parser.parse_args() | |
blob_commands(args) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment