TasmotaManager/docs/migrate_to_refactored.py
Mike Geppert dec72de4e0 Organize: Move refactoring helper files to docs/
- Moved tasmota_manager_refactor_notes.md to docs/REFACTORING_NOTES.md
- Moved migrate_to_refactored.py to docs/ for future reference
- Moved GitWorkflowRefactor.sh to docs/ for future reference
2025-10-29 16:51:17 +00:00

117 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Migration script to organize files into the new refactored structure."""
import os
import shutil
import sys
def ensure_dir(path):
"""Ensure directory exists."""
os.makedirs(path, exist_ok=True)
def move_file(src, dst, dry_run=False):
"""Move a file if it exists."""
if os.path.exists(src):
if dry_run:
print(f"Would move: {src} -> {dst}")
else:
ensure_dir(os.path.dirname(dst))
shutil.move(src, dst)
print(f"Moved: {src} -> {dst}")
return True
return False
def delete_file(path, dry_run=False):
"""Delete a file if it exists."""
if os.path.exists(path):
if dry_run:
print(f"Would delete: {path}")
else:
os.remove(path)
print(f"Deleted: {path}")
return True
return False
def main():
"""Run migration."""
dry_run = '--dry-run' in sys.argv
if dry_run:
print("DRY RUN MODE - No files will be moved or deleted\n")
print("TasmotaManager Migration Script")
print("=" * 60)
# Ensure directories exist
print("\n1. Creating directories...")
ensure_dir('data')
ensure_dir('data/temp')
ensure_dir('docs')
ensure_dir('tests')
# Move documentation files to docs/
print("\n2. Moving documentation files to docs/...")
doc_files = [
'CONSOLE_COMMANDS.md',
'KNOWN_ISSUES.md',
'blank_template_value_handling.md',
'console_settings_optimization.md',
'GITLAB_MIGRATION.md',
'rule1_device_mode_verification.md',
'self_reported_hostname_locations.md',
'is_device_excluded_implementation.py'
]
for doc_file in doc_files:
move_file(doc_file, f'docs/{doc_file}', dry_run)
# Move data files to data/
print("\n3. Moving data files to data/...")
data_files = [
'current.json',
'current.json.backup',
'deprecated.json',
'TasmotaDevices.json',
'TasmotaHostnameReport.json',
'device_mode_mqtt_summary.txt',
'mqtt_device_mode_analysis.txt',
'git_diff.txt'
]
for data_file in data_files:
move_file(data_file, f'data/{data_file}', dry_run)
# Delete old Python files (assuming they're committed to git)
print("\n4. Removing old Python files...")
old_files = [
'TasmotaManager.py',
'TasmotaManager_fixed.py'
]
for old_file in old_files:
delete_file(old_file, dry_run)
# Delete temporary migration scripts
print("\n5. Removing temporary migration files...")
temp_files = [
'file_migration_script.py',
'refactoring_verification.py'
]
for temp_file in temp_files:
delete_file(temp_file, dry_run)
print("\n" + "=" * 60)
if dry_run:
print("DRY RUN COMPLETE - Run without --dry-run to apply changes")
else:
print("MIGRATION COMPLETE!")
print("\nNext steps:")
print("1. Test the new modules: python main.py --help")
print("2. Commit the changes: git add -A && git commit -m 'Refactor: Split into modular structure'")
print("3. The old TasmotaManager.py is in git history if you need it")
print("=" * 60)
if __name__ == '__main__':
main()