Trainer_LLM/scripts/restore_single_file.py

37 lines
1.1 KiB
Python
Raw Permalink 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 Kategorie und Dateinamen an, z.B.:")
print(" python restore_single_file.py karatetrainer mae_geri.txt")
sys.exit(1)
# Eingabe prüfen
if len(sys.argv) != 3:
print_usage()
CATEGORY = sys.argv[1]
FILENAME = sys.argv[2]
SOURCE_DIR = os.path.expanduser(f"~/knowledge/{CATEGORY}/_imported")
TARGET_DIR = os.path.expanduser(f"~/knowledge/{CATEGORY}")
SOURCE_FILE = os.path.join(SOURCE_DIR, FILENAME)
TARGET_FILE = os.path.join(TARGET_DIR, FILENAME)
if not os.path.isfile(SOURCE_FILE):
print(f"❌ Die Datei '{FILENAME}' wurde im Archivordner '{SOURCE_DIR}' nicht gefunden.")
sys.exit(1)
if os.path.exists(TARGET_FILE):
confirm = input(f"⚠️ Datei '{FILENAME}' existiert im Zielordner. Überschreiben? [j/N] ").strip().lower()
if confirm != "j":
print("⏹️ Abgebrochen.")
sys.exit(0)
try:
shutil.move(SOURCE_FILE, TARGET_FILE)
print(f"'{FILENAME}' wurde zurück nach '{TARGET_DIR}' verschoben.")
except Exception as e:
print(f"❌ Fehler beim Verschieben: {e}")