Atlas / scripts /utilities /archive_migration_files.py
findEthics
Complete codebase cleanup and project structure validation
f0b765c
Raw
History Blame Contribute Delete
4.95 kB
#!/usr/bin/env python3
"""
Archive Migration Files Script
This script moves completed migration files to the archive directory
to clean up the main codebase while preserving historical context.
Usage:
python scripts/archive_migration_files.py [--dry-run]
Options:
--dry-run Show what would be moved without actually moving files
"""
import argparse
from pathlib import Path
import shutil
class MigrationArchiver:
"""Handles archiving of completed migration files."""
def __init__(self, dry_run=False):
self.dry_run = dry_run
self.root_dir = Path.cwd()
self.archive_dir = self.root_dir / "archive"
self.migration_files = [
"migrate_user_authentication.py",
"rollback_user_authentication.py",
"validate_user_migration.py"
]
self.migration_dirs = [
"migration_backups"
]
def create_archive_structure(self):
"""Create the archive directory structure."""
if not self.dry_run:
self.archive_dir.mkdir(exist_ok=True)
print(f"✓ Created archive directory: {self.archive_dir}")
else:
print(f"[DRY RUN] Would create archive directory: {self.archive_dir}")
def archive_file(self, source_path, relative_path=None):
"""Archive a single file to the archive directory."""
source = Path(source_path)
if not source.exists():
print(f"⚠ File not found: {source}")
return False
if relative_path:
dest = self.archive_dir / relative_path
else:
dest = self.archive_dir / source.name
if self.dry_run:
print(f"[DRY RUN] Would move: {source} -> {dest}")
return True
# Create destination directory if needed
dest.parent.mkdir(parents=True, exist_ok=True)
try:
shutil.move(str(source), str(dest))
print(f"✓ Archived: {source} -> {dest}")
return True
except Exception as e:
print(f"✗ Failed to archive {source}: {e}")
return False
def archive_directory(self, source_path, relative_path=None):
"""Archive an entire directory to the archive directory."""
source = Path(source_path)
if not source.exists():
print(f"⚠ Directory not found: {source}")
return False
if relative_path:
dest = self.archive_dir / relative_path
else:
dest = self.archive_dir / source.name
if self.dry_run:
print(f"[DRY RUN] Would move directory: {source} -> {dest}")
return True
try:
shutil.move(str(source), str(dest))
print(f"✓ Archived directory: {source} -> {dest}")
return True
except Exception as e:
print(f"✗ Failed to archive directory {source}: {e}")
return False
def run_archival(self):
"""Execute the archival process."""
print("Starting migration file archival process...")
print(f"Archive directory: {self.archive_dir}")
print(f"Dry run mode: {self.dry_run}")
print("-" * 50)
# Create archive structure
self.create_archive_structure()
# Archive individual migration files
archived_files = 0
for file_name in self.migration_files:
if self.archive_file(file_name):
archived_files += 1
# Archive migration directories
archived_dirs = 0
for dir_name in self.migration_dirs:
if self.archive_directory(dir_name):
archived_dirs += 1
print("-" * 50)
print(f"Archival complete!")
print(f"Files archived: {archived_files}/{len(self.migration_files)}")
print(f"Directories archived: {archived_dirs}/{len(self.migration_dirs)}")
if self.dry_run:
print("\nThis was a dry run. Use without --dry-run to actually move files.")
return archived_files + archived_dirs > 0
def main():
"""Main entry point for the archival script."""
parser = argparse.ArgumentParser(
description="Archive completed migration files to clean up codebase"
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Show what would be moved without actually moving files"
)
args = parser.parse_args()
archiver = MigrationArchiver(dry_run=args.dry_run)
success = archiver.run_archival()
if not success and not args.dry_run:
print("⚠ Some files could not be archived. Check the output above.")
return 1
return 0
if __name__ == "__main__":
exit(main())