tessl install tessl/pypi-gcloud@0.7.0Python client library for Google Cloud Platform services including Datastore, Storage, and Pub/Sub
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.19x
Baseline
Agent success rate without this tile
78%
Build a Python script that analyzes files in a cloud storage bucket and generates a report categorizing them by file extension and size.
Your script should connect to a cloud storage bucket and:
.txt, .jpg, .pdf)The script should accept two command-line arguments:
project_id: The Google Cloud project IDbucket_name: The name of the bucket to analyzeExample usage:
python storage_analyzer.py my-project my-bucketThe output should be formatted as:
Storage Analysis Report
=======================
Extension: .jpg
Count: 15 files
Total Size: 2458320 bytes
Extension: .pdf
Count: 3 files
Total Size: 1024000 bytes
Extension: .txt
Count: 8 files
Total Size: 45120 bytes.txt, .jpg, and .pdf, the report correctly categorizes and counts them @test@generates
def analyze_bucket(project_id: str, bucket_name: str) -> dict:
"""
Analyzes all files in a cloud storage bucket and returns categorized data.
Args:
project_id: Google Cloud project ID
bucket_name: Name of the bucket to analyze
Returns:
Dictionary with extension as key and dict containing 'count' and 'total_size'
"""
pass
def print_report(analysis_data: dict) -> None:
"""
Prints a formatted report from the analysis data.
Args:
analysis_data: Dictionary from analyze_bucket function
"""
pass
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print("Usage: python storage_analyzer.py <project_id> <bucket_name>")
sys.exit(1)
project_id = sys.argv[1]
bucket_name = sys.argv[2]
data = analyze_bucket(project_id, bucket_name)
print_report(data)Provides Google Cloud Platform client libraries for accessing cloud storage services.