Trainer_LLM/scripts/restore_imported_files.py

46 lines
1.3 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
import shutil
def print_usage():
print("❌ Bitte gib eine Kategorie an, z.B.:")
print(" python restore_imported_files.py karatetrainer")
sys.exit(1)
# --- Eingabe prüfen ---
if len(sys.argv) < 2:
print_usage()
CATEGORY = sys.argv[1]
FORCE = "--force" in sys.argv
SOURCE_DIR = os.path.expanduser(f"~/knowledge/{CATEGORY}/_imported")
TARGET_DIR = os.path.expanduser(f"~/knowledge/{CATEGORY}")
if not os.path.isdir(SOURCE_DIR):
print(f"❌ Quellordner '{SOURCE_DIR}' existiert nicht.")
sys.exit(1)
files = [f for f in os.listdir(SOURCE_DIR) if os.path.isfile(os.path.join(SOURCE_DIR, f))]
if not files:
print("⚠️ Keine Dateien zum Wiederherstellen gefunden.")
sys.exit(0)
print(f"♻️ Wiederherstellung von {len(files)} Dateien nach '{TARGET_DIR}'")
restored = 0
for file in files:
source_path = os.path.join(SOURCE_DIR, file)
target_path = os.path.join(TARGET_DIR, file)
if not FORCE:
confirm = input(f"🔁 Datei '{file}' zurückkopieren? [j/N] ").strip().lower()
if confirm != "j":
continue
shutil.move(source_path, target_path)
print(f"'{file}' wurde zurückkopiert.")
restored += 1
print(f"\n🎉 {restored} Datei(en) wurden erfolgreich wiederhergestellt.")