Skip to content

Instantly share code, notes, and snippets.

@vsoch

vsoch/download.py

Created Nov 2, 2019
Embed
What would you like to do?
Provides a wrapper script to download a Snakemake Blob, and then extract to a location. This should be moved to be packaged alongside snakemake
#!/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
You can’t perform that action at this time.