@@ -19,75 +19,65 @@ def list_files() -> List[Optional[str]]:
1919 """
2020 List all objects with file extension in a GCP bucket.
2121
22- :param str bucket_name: Human-readable GCP bucket name.
23- :param str bucket_dir: Bucket directory in which object exists.
24-
2522 :returns: List[Optional[str]]
2623 """
2724 blobs = bucket .list_blobs (prefix = BUCKET_DIR )
2825 blob_file_list = [blob .name for blob in blobs if "." in blob .name ]
2926 return blob_file_list
3027
3128
32- def pick_random_file () -> str :
29+ def pick_random_file () -> Tuple [ Blob , str ] :
3330 """
3431 Pick a `random` file from GCP bucket.
3532
36- :param str bucket_name: Human-readable GCP bucket name.
37-
38- :returns: str
33+ :returns: Tuple[Blob, str]
3934 """
4035 blobs = list_files ()
4136 rand = randint (0 , len (blobs ) - 1 )
4237 blob = bucket .blob (blobs [rand ])
4338 return blob , blob .name
4439
4540
46- def download_random_file (local_dir : str ) -> Tuple [ Blob , str ] :
41+ def download_random_file (local_dir : str ) -> None :
4742 """
4843 Download random file from GCP bucket.
4944
50- :param str bucket_name: Human-readable GCP bucket name.
51- :param str bucket_dir: Bucket directory in which object exists.
5245 :param str local_dir: Local file path to upload/download files.
5346
54- :returns: str
47+ :returns: None
5548 """
5649 blob , blob_filename = pick_random_file ()
5750 blob .download_to_filename (f"{ local_dir } /{ blob .name .split ('/' )[- 1 ]} " )
58- return blob , blob_filename
51+ print ( f"Downloaded { blob_filename } to ` { local_dir } `." )
5952
6053
61- def delete_file (bucket_name : str ) -> str :
54+ def delete_file (bucket_name : str ) -> None :
6255 """
6356 Delete file from GCP bucket.
6457
6558 :param str bucket_name: Human-readable GCP bucket name.
66- :param str bucket_dir: Bucket directory in which object exists.
6759
68- :returns: str
60+ :returns: None
6961 """
7062 blob , blob_filename = pick_random_file ()
7163 bucket .delete_blob (blob_filename )
72- return f"{ blob_filename } deleted from bucket: { bucket_name } ."
64+ print ( f"{ blob_filename } deleted from bucket: { bucket_name } ." )
7365
7466
75- def rename_file (new_filename : str ) -> str :
67+ def rename_file (new_filename : str ) -> None :
7668 """
7769 Rename a file in GCP bucket.
7870
79- :param str bucket_name: Human-readable GCP bucket name.
80- :param str bucket_dir: Bucket directory from which to extract object.
8171 :param str new_filename: New file name for Blob object.
8272
83- :returns: str
73+ :returns: None
8474 """
8575 blob , blob_filename = pick_random_file ()
8676 bucket .rename_blob (blob , new_name = new_filename )
87- return f"{ blob_filename } renamed to { new_filename } ."
77+ print ( f"{ blob_filename } renamed to { new_filename } ." )
8878
8979
90- def upload_files (bucket_name : str , bucket_dir : str , local_dir : str ) -> str :
80+ def upload_files (bucket_name : str , bucket_dir : str , local_dir : str ) -> None :
9181 """
9282 Upload files to GCP bucket.
9383
@@ -100,7 +90,6 @@ def upload_files(bucket_name: str, bucket_dir: str, local_dir: str) -> str:
10090 files = [f for f in listdir (local_dir ) if isfile (join (local_dir , f ))]
10191 for file in files :
10292 local_file = f"{ local_dir } /{ file } "
103- print (f"local file = { local_file } \n " )
10493 blob = bucket .blob (f"{ bucket_dir } /{ file } " )
10594 blob .upload_from_filename (local_file )
106- return f"Uploaded { files } to '{ bucket_name } ' bucket."
95+ print ( f"Uploaded { files } to '{ bucket_name } ' bucket." )
0 commit comments