defupload_blob(source_file_name, destination_blob_name): """Uploads a file to the bucket.""" blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format( source_file_name, destination_blob_name))
defdownload_blob(source_blob_name, destination_file_name): """Downloads a blob from the bucket.""" blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print('Blob {} downloaded to {}.'.format( source_blob_name, destination_file_name))
deffind_all_files_with_prefix(local_prefix='public', prefix=''): name_list = os.listdir(os.path.join(local_prefix, prefix)) ans_list = [] for name in name_list: if name in IGNORE_LIST: continue if os.path.isdir(os.path.join(local_prefix, os.path.join(prefix, name))): ans_list.extend(find_all_files_with_prefix(local_prefix, os.path.join(prefix, name))) else: ans_list.append(os.path.join(prefix, name)) return ans_list
defmain(): local_prefix = 'public' file_names = find_all_files_with_prefix(local_prefix) for file_name in file_names: upload_blob(os.path.join(local_prefix, file_name), file_name) return