diff --git a/upload_to_google_storage_first_class.py b/upload_to_google_storage_first_class.py index f0d53368c..68ae3f834 100755 --- a/upload_to_google_storage_first_class.py +++ b/upload_to_google_storage_first_class.py @@ -171,6 +171,10 @@ def main(): parser.add_option('-b', '--bucket', help='Google Storage bucket to upload to.') + parser.add_option('-p', + '--prefix', + help='Prefix that goes before object-name (i.e. in ' + 'between bucket and object name).') parser.add_option('-o', '--object-name', help='Optional object name of uploaded tar file. ' @@ -233,6 +237,9 @@ def main(): if not object_name: object_name = get_sha256sum(file) + if options.prefix: + object_name = f'{options.prefix}/{object_name}' + # Make sure we can find a working instance of gsutil. if os.path.exists(GSUTIL_DEFAULT_PATH): gsutil = Gsutil(GSUTIL_DEFAULT_PATH, boto_path=options.boto) @@ -255,7 +262,9 @@ def main(): gsutil.check_call('version') return gsutil.call('config') - base_url = 'gs://%s' % options.bucket + assert '/' not in options.bucket, "Slashes not allowed in bucket name" + + base_url = f'gs://{options.bucket}' generation = upload_to_google_storage(file, base_url, object_name, gsutil, options.force, options.gzip,