#!/usr/bin/env python3 """ Simple script to archive all Daytona sandboxes with "STOPPED" state. Usage: python archive_stopped_sandboxes.py [--dry-run] """ import sys import argparse import json import re from datetime import datetime from utils.config import config try: from daytona import Daytona except ImportError: print("Error: Daytona Python SDK not found. Please install it with: pip install daytona") sys.exit(1) def save_raw_list_as_json(raw_list, filename=None): """Save raw list output as JSON file.""" if filename is None: timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") filename = f"raw_sandboxes_{timestamp}.json" print(f"Saving raw list output to {filename}") try: with open(filename, 'w') as f: json.dump(raw_list, f, indent=2, default=str) print(f"✓ Successfully saved raw list to {filename}") return filename except Exception as e: print(f"✗ Failed to save JSON file: {e}") return None def parse_sandbox_string(sandbox_str): """Parse sandbox string representation to extract ID and state.""" # Extract ID using regex id_match = re.search(r"id='([^']+)'", sandbox_str) sandbox_id = id_match.group(1) if id_match else None # Extract state using regex state_match = re.search(r"state=