File size: 6,354 Bytes
c922f8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python
"""
GAIA Project File Organizer

This script organizes files in the GAIA project by moving them to appropriate directories:
1. Moves deployment-related files to the deployment directory
2. Moves example notebooks to the examples directory
3. Moves utility scripts to the utils directory

Usage:
    python src/gaia/utils/cli/organize_files.py [--dry-run]
"""

import os
import sys
import shutil
import logging
import argparse
from pathlib import Path
from typing import Dict, List, Tuple

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(levelname)s - %(message)s",
    handlers=[
        logging.StreamHandler()
    ]
)
logger = logging.getLogger("organize_files")

# Files to move to deployment directory
DEPLOYMENT_FILES = [
    "prepare_for_hf_deployment.py",
    "hf_deployment_instructions.md",
    "huggingface_space_deployment_guide.md",
    "huggingface_space_update_guide.md",
    "huggingface_space_update_guide.md",
    "huggingface_space_cleanup.md",
    "huggingface_space_deployment_summary.md",
    "space_config.json",
    "deploy_to_hf.py",
    "deploy_to_huggingface_credential.py",
    "deploy_to_huggingface_dotenv.py",
    "deploy_to_huggingface_env.py",
    "deploy_to_huggingface.py",
    "deploy_with_token.py",
    "deployment_checklist.md",
    "deployment_readiness_report.json",
    "deployment_readiness_report.md",
    "deployment_verification.py",
    "final_deployment_guide.md",
    "complete_deployment_guide.md",
    "complete_deployment_solution.md",
    "get_huggingface_token.py",
    "test_deployment_readiness.py",
    "verify_deployment_readiness.py",
    "production_cleanup.py",
    "production_readiness_check.py",
    "production_test.py",
    "production_verification_report.md",
]

# Example notebooks to move to examples directory
EXAMPLE_FILES = [
    "mail_sorting.ipynb",
    "agent.ipynb"
]

# Utility scripts to move to utils directory
UTIL_FILES = [
    "generate_env_template.py",
    "fix_encoding.py",
    "fix_graph_imports.py",
    "remove_debug_statements.py",
    "remove_duplicate_tests.py",
    "run_verification_tests.py",
    "simple_memory_test.py",
    "simple_test.py",
    "validate_app_simple.py",
    "validate_app.py",
    "update_agent.py",
    "verify_components.py",
    "verify_minimal.py",
    "create_env_and_test.py"
]

def move_file(src: str, dest_dir: str, dry_run: bool = False) -> bool:
    """
    Move a file to the specified directory
    
    Args:
        src: Source file path
        dest_dir: Destination directory
        dry_run: If True, only show what would be moved without making changes
        
    Returns:
        bool: True if successful or would be successful, False otherwise
    """
    if not os.path.exists(src):
        logger.warning(f"Source file does not exist: {src}")
        return False
        
    if not os.path.exists(dest_dir):
        if dry_run:
            logger.info(f"DRY RUN: Would create directory: {dest_dir}")
        else:
            os.makedirs(dest_dir, exist_ok=True)
            logger.info(f"Created directory: {dest_dir}")
    
    dest_path = os.path.join(dest_dir, os.path.basename(src))
    
    if dry_run:
        logger.info(f"DRY RUN: Would move {src} -> {dest_path}")
        return True
        
    try:
        shutil.move(src, dest_path)
        logger.info(f"Moved {src} -> {dest_path}")
        return True
    except Exception as e:
        logger.error(f"Error moving {src} to {dest_path}: {str(e)}")
        return False

def main():
    """Main function to organize files."""
    parser = argparse.ArgumentParser(description="GAIA Project File Organizer")
    parser.add_argument("--dry-run", action="store_true", help="Show what would be moved without making changes")
    args = parser.parse_args()
    
    if args.dry_run:
        logger.info("Running in DRY RUN mode - no files will be moved")
    
    # Track results
    results = {
        "deployment": {"success": 0, "failed": 0, "missing": 0},
        "examples": {"success": 0, "failed": 0, "missing": 0},
        "utils": {"success": 0, "failed": 0, "missing": 0}
    }
    
    # Move deployment files
    logger.info("\n=== Moving deployment files ===")
    for file in DEPLOYMENT_FILES:
        if os.path.exists(file):
            success = move_file(file, "deployment", args.dry_run)
            if success:
                results["deployment"]["success"] += 1
            else:
                results["deployment"]["failed"] += 1
        else:
            logger.info(f"File not found (skipping): {file}")
            results["deployment"]["missing"] += 1
    
    # Move example files
    logger.info("\n=== Moving example files ===")
    for file in EXAMPLE_FILES:
        if os.path.exists(file):
            success = move_file(file, "examples", args.dry_run)
            if success:
                results["examples"]["success"] += 1
            else:
                results["examples"]["failed"] += 1
        else:
            logger.info(f"File not found (skipping): {file}")
            results["examples"]["missing"] += 1
    
    # Move utility files
    logger.info("\n=== Moving utility files ===")
    for file in UTIL_FILES:
        if os.path.exists(file):
            success = move_file(file, "utils", args.dry_run)
            if success:
                results["utils"]["success"] += 1
            else:
                results["utils"]["failed"] += 1
        else:
            logger.info(f"File not found (skipping): {file}")
            results["utils"]["missing"] += 1
    
    # Print summary
    logger.info("\n=== File Organization Summary ===")
    logger.info(f"Deployment Files: {results['deployment']['success']} moved, {results['deployment']['failed']} failed, {results['deployment']['missing']} not found")
    logger.info(f"Example Files: {results['examples']['success']} moved, {results['examples']['failed']} failed, {results['examples']['missing']} not found")
    logger.info(f"Utility Files: {results['utils']['success']} moved, {results['utils']['failed']} failed, {results['utils']['missing']} not found")
    
    # Return success code if no failures
    total_failures = sum(result["failed"] for result in results.values())
    return 0 if total_failures == 0 else 1

if __name__ == "__main__":
    sys.exit(main())