From 220b14898ec30d44655270af080c3f2429325227 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Mon, 1 Sep 2025 17:27:48 +0000 Subject: [PATCH 1/2] Add argparse so that the samples can be run as a a standalone script --- ...sfer_manager_upload_chunks_concurrently.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py b/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py index 009f09648..a4abd13b9 100644 --- a/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py +++ b/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import argparse + # [START storage_transfer_manager_upload_chunks_concurrently] def upload_chunks_concurrently( @@ -54,4 +56,40 @@ def upload_chunks_concurrently( print(f"File {source_filename} uploaded to {destination_blob_name}.") +if __name__ == "__main__": + argparse = argparse.ArgumentParser( + description="Upload a file to GCS in chunks concurrently." + ) + argparse.add_argument( + "--bucket_name", help="The name of the GCS bucket to upload to." + ) + argparse.add_argument( + "--source_filename", help="The local path to the file to upload." + ) + argparse.add_argument( + "--destination_blob_name", help="The name of the object in GCS." + ) + argparse.add_argument( + "--chunk_size", + type=int, + default=32 * 1024 * 1024, + help="The size of each chunk in bytes (default: 32 MiB). The remote\ + service has a minimum of 5 MiB and a maximum of 5 GiB", + ) + argparse.add_argument( + "--workers", + type=int, + default=8, + help="The number of worker processes to use (default: 8).", + ) + args = argparse.parse_args() + upload_chunks_concurrently( + args.bucket_name, + args.source_filename, + args.destination_blob_name, + args.chunk_size, + args.workers, + ) + + # [END storage_transfer_manager_upload_chunks_concurrently] From 554b26a212701bf93b1396bd33dea5ca84a0e9e3 Mon Sep 17 00:00:00 2001 From: Chandra Sirimala Date: Mon, 1 Sep 2025 17:27:48 +0000 Subject: [PATCH 2/2] Add argparse to run samples as script a standalone script --- ...sfer_manager_upload_chunks_concurrently.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py b/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py index 009f09648..a4abd13b9 100644 --- a/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py +++ b/samples/snippets/storage_transfer_manager_upload_chunks_concurrently.py @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import argparse + # [START storage_transfer_manager_upload_chunks_concurrently] def upload_chunks_concurrently( @@ -54,4 +56,40 @@ def upload_chunks_concurrently( print(f"File {source_filename} uploaded to {destination_blob_name}.") +if __name__ == "__main__": + argparse = argparse.ArgumentParser( + description="Upload a file to GCS in chunks concurrently." + ) + argparse.add_argument( + "--bucket_name", help="The name of the GCS bucket to upload to." + ) + argparse.add_argument( + "--source_filename", help="The local path to the file to upload." + ) + argparse.add_argument( + "--destination_blob_name", help="The name of the object in GCS." + ) + argparse.add_argument( + "--chunk_size", + type=int, + default=32 * 1024 * 1024, + help="The size of each chunk in bytes (default: 32 MiB). The remote\ + service has a minimum of 5 MiB and a maximum of 5 GiB", + ) + argparse.add_argument( + "--workers", + type=int, + default=8, + help="The number of worker processes to use (default: 8).", + ) + args = argparse.parse_args() + upload_chunks_concurrently( + args.bucket_name, + args.source_filename, + args.destination_blob_name, + args.chunk_size, + args.workers, + ) + + # [END storage_transfer_manager_upload_chunks_concurrently]