92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
EXECUTE RENAME - Dejansko preimenuje vse slike
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path("/Users/davidkotnik/repos/novafarma")
|
|
|
|
def execute_rename():
|
|
"""Izvede mass rename"""
|
|
# Naloži rename map
|
|
print("📂 Nalagam rename map...")
|
|
with open(PROJECT_ROOT / "rename_map.json", 'r', encoding='utf-8') as f:
|
|
rename_map = json.load(f)
|
|
|
|
print(f"✅ Naloženih: {len(rename_map)} preimenovanj\n")
|
|
|
|
print("⚠️ ZAČENJAM PREIMENOVANJE...\n")
|
|
print("=" * 80)
|
|
|
|
success = 0
|
|
errors = []
|
|
skipped = 0
|
|
|
|
for old_rel, new_rel in rename_map.items():
|
|
old_path = PROJECT_ROOT / old_rel
|
|
new_path = PROJECT_ROOT / new_rel
|
|
|
|
# Preveri če obstaja
|
|
if not old_path.exists():
|
|
errors.append(f"❌ Ne najdem: {old_rel}")
|
|
continue
|
|
|
|
# Preveri če nova že obstaja
|
|
if new_path.exists() and new_path != old_path:
|
|
skipped += 1
|
|
continue
|
|
|
|
# Preimenuj
|
|
try:
|
|
# Create parent directory if needed
|
|
new_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Rename
|
|
old_path.rename(new_path)
|
|
success += 1
|
|
|
|
# Progress indicator
|
|
if success % 500 == 0:
|
|
print(f"✅ {success}/{len(rename_map)} preimenovanih...")
|
|
|
|
except Exception as e:
|
|
errors.append(f"❌ Napaka pri {old_rel}: {e}")
|
|
|
|
# Final report
|
|
print("=" * 80)
|
|
print("\n📊 KONČNO POROČILO:")
|
|
print("=" * 80)
|
|
print(f"✅ Uspešno preimenovanih: {success}")
|
|
print(f"⚠️ Preskočenih (že obstajajo): {skipped}")
|
|
print(f"❌ Napak: {len(errors)}")
|
|
print("=" * 80)
|
|
|
|
if errors and len(errors) <= 50:
|
|
print("\n❌ NAPAKE:")
|
|
for err in errors[:50]:
|
|
print(f" {err}")
|
|
if len(errors) > 50:
|
|
print(f" ... in še {len(errors) - 50} napak")
|
|
|
|
# Save log
|
|
log_file = PROJECT_ROOT / "rename_execution_log.txt"
|
|
with open(log_file, 'w', encoding='utf-8') as f:
|
|
f.write(f"MASS RENAME EXECUTION LOG\n")
|
|
f.write(f"{'=' * 80}\n\n")
|
|
f.write(f"Uspešno: {success}\n")
|
|
f.write(f"Preskočeno: {skipped}\n")
|
|
f.write(f"Napak: {len(errors)}\n\n")
|
|
|
|
if errors:
|
|
f.write(f"NAPAKE:\n")
|
|
for err in errors:
|
|
f.write(f"{err}\n")
|
|
|
|
print(f"\n📄 Log shranjen: rename_execution_log.txt")
|
|
print("\n🎉 PREIMENOVANJE KONČANO!")
|
|
|
|
if __name__ == "__main__":
|
|
execute_rename()
|