Skip to content

Commit a655d6b

Browse files
authored
docs: address sample feedback issues (#5329)
## Description Fixes #5180, captures work from #5181 authored by @keegan2149, thank you! ## Checklist - [x] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [x] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [x] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [x] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [x] Please **merge** this PR for me once it is approved.
1 parent 2db93f8 commit a655d6b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

storage/cloud-client/snippets_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,13 @@ def test_object_get_kms_key(test_bucket):
405405

406406
def test_storage_compose_file(test_bucket):
407407
source_files = ["test_upload_blob_1", "test_upload_blob_2"]
408-
blob_list = []
409408
for source in source_files:
410409
blob = test_bucket.blob(source)
411410
blob.upload_from_string(source)
412-
blob_list.append(blob)
413411

414412
with tempfile.NamedTemporaryFile() as dest_file:
415413
destination = storage_compose_file.compose_file(
416-
test_bucket.name, blob_list, dest_file.name
414+
test_bucket.name, source_files[0], source_files[1], dest_file.name
417415
)
418416
composed = destination.download_as_string()
419417

storage/cloud-client/storage_change_file_storage_class.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# [START storage_change_file_storage_class]
2020
from google.cloud import storage
21-
from google.cloud.storage import constants
2221

2322

2423
def change_file_storage_class(bucket_name, blob_name):
@@ -30,7 +29,7 @@ def change_file_storage_class(bucket_name, blob_name):
3029

3130
bucket = storage_client.get_bucket(bucket_name)
3231
blob = bucket.get_blob(blob_name)
33-
blob.update_storage_class(constants.NEARLINE_STORAGE_CLASS)
32+
blob.update_storage_class("NEARLINE")
3433

3534
print(
3635
"Blob {} in bucket {} had its storage class set to {}".format(

storage/cloud-client/storage_compose_file.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,25 @@
2020
from google.cloud import storage
2121

2222

23-
def compose_file(bucket_name, sources, destination_blob_name):
23+
def compose_file(bucket_name, first_blob_name, second_blob_name, destination_blob_name):
2424
"""Concatenate source blobs into destination blob."""
2525
# bucket_name = "your-bucket-name"
26-
# sources = [blob_1, blob_2]
26+
# first_blob_name = "first-object-name"
27+
# second_blob_name = "second-blob-name"
2728
# destination_blob_name = "destination-object-name"
2829

2930
storage_client = storage.Client()
3031
bucket = storage_client.bucket(bucket_name)
3132
destination = bucket.blob(destination_blob_name)
3233
destination.content_type = "text/plain"
34+
35+
# sources is a list of Blob instances, up to the max of 32 instances per request
36+
sources = [bucket.get_blob(first_blob_name), bucket.get_blob(second_blob_name)]
3337
destination.compose(sources)
3438

3539
print(
36-
"Composed new object {} in the bucket {}".format(
37-
destination_blob_name, bucket.name
40+
"New composite object {} in the bucket {} was created by combining {} and {}".format(
41+
destination_blob_name, bucket_name, first_blob_name, second_blob_name
3842
)
3943
)
4044
return destination
@@ -44,5 +48,8 @@ def compose_file(bucket_name, sources, destination_blob_name):
4448

4549
if __name__ == "__main__":
4650
compose_file(
47-
bucket_name=sys.argv[1], sources=sys.argv[2], destination_blob_name=sys.argv[3],
51+
bucket_name=sys.argv[1],
52+
first_blob_name=sys.argv[2],
53+
second_blob_name=sys.argv[3],
54+
destination_blob_name=sys.argv[4],
4855
)

0 commit comments

Comments
 (0)