import os import subprocess def run_git_move(): print("=== Безопасная миграция файлов в структуру проекта ===") # Словарь: имя файла -> целевая папка file_mapping = { "database.py": "core/database.py", "scud_export.py": "services/scud_export.py", "share_copier.py": "services/share_copier.py", "data_loader.py": "services/data_loader.py", "data_validator.py": "services/data_validator.py", "zup_extractor.py": "services/zup_extractor.py", "ai_verifier.py": "services/ai_verifier.py", "excel_exporter.py": "services/excel_exporter.py", "text_reporter.py": "services/text_reporter.py", "feedback_loop.py": "services/feedback_loop.py", "knowledge_base.py": "services/knowledge_base.py", "db_cli.py": "scripts/db_cli.py" } # Убедимся, что папки существуют и содержат __init__.py for folder in ["core", "services", "api", "frontend", "scripts"]: os.makedirs(folder, exist_ok=True) init_file = os.path.join(folder, "__init__.py") if not os.path.exists(init_file): open(init_file, 'w').close() for filename, dest in file_mapping.items(): # Проверим, где файл может находиться: в корне или уже в папке назначения if os.path.exists(filename): src = filename elif os.path.exists(dest): print(f"[ℹ️ Уже на месте] {dest}") continue else: # Попробуем поискать файл рекурсивно found = None for root, dirs, files in os.walk("."): if filename in files and "venv" not in root: found = os.path.join(root, filename) break src = found if src and os.path.exists(src): if src == dest: continue dest_dir = os.path.dirname(dest) os.makedirs(dest_dir, exist_ok=True) try: subprocess.run(["git", "mv", src, dest], check=True) print(f"[git mv] Успешно перемещен: {src} -> {dest}") except subprocess.CalledProcessError as e: print(f"[⚠️ Ошибка] Не удалось переместить через git mv {src}: {e}") else: print(f"[❌ Не найден] Файл {filename} не обнаружен в репозитории.") print("\n=== Миграция завершена. Выполните 'git status' для проверки ===") if __name__ == "__main__": run_git_move()