or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/gcloud@0.7.x
tile.json

tessl/pypi-gcloud

tessl install tessl/pypi-gcloud@0.7.0

Python 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%

task.mdevals/scenario-2/

Cloud Storage File Organizer

Build a Python script that analyzes files in a cloud storage bucket and generates a report categorizing them by file extension and size.

Requirements

Your script should connect to a cloud storage bucket and:

  1. List all files in the bucket
  2. Categorize files by their extension (e.g., .txt, .jpg, .pdf)
  3. Calculate the total size for each file extension category
  4. Print a summary report showing:
    • Each file extension found
    • The number of files with that extension
    • The total size (in bytes) for files with that extension
    • Files sorted by extension name alphabetically

Input

The script should accept two command-line arguments:

  • project_id: The Google Cloud project ID
  • bucket_name: The name of the bucket to analyze

Example usage:

python storage_analyzer.py my-project my-bucket

Output Format

The 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

Test Cases

  • When the bucket contains files with extensions .txt, .jpg, and .pdf, the report correctly categorizes and counts them @test
  • When the bucket contains multiple files with the same extension, the total size is calculated correctly @test
  • When the bucket is empty, the report displays a message "No files found in bucket" @test

Implementation

@generates

API

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)

Dependencies { .dependencies }

gcloud { .dependency }

Provides Google Cloud Platform client libraries for accessing cloud storage services.