Files
novafarma/scripts/organize_everything.py
2026-01-20 01:05:17 +01:00

108 lines
3.6 KiB
Python

import os
import shutil
import re
ROOT = "assets/slike"
# Configuration for each folder
CONFIG = {
"liki": [
(r"kai", "Kai"),
(r"ana", "Ana"),
(r"gronk", "Gronk"),
(r"(npc|druid|witch|farmer|baker|priest|guide|merchant|trader|kid|man|woman|girl|boy)", "NPCs"),
(r".*", "Ostalo")
],
"teren": [
(r"(tree|bush|flower|plant|rastlina|drevo)", "Rastline"),
(r"(grass|ground|soil|dirt|sand|tileset|trava|zemlja)", "Tla"),
(r"(water|voda|river|lake)", "Voda"),
(r"(stone|rock|kamen|skala)", "Kamni"),
(r"(house|building|wall|ruin|fence|zgradba|his|hiš)", "Zgradbe"),
(r"(prop|lamp|sign|cart)", "Props"),
(r".*", "Ostalo")
],
"predmeti": [
(r"(tool|axe|pickaxe|hoe|watering|orodje|kramp|sekira)", "Orodje"),
(r"(weapon|sword|bow|arrow|gun|rifle|orozje|meč)", "Orozje"),
(r"(seed|seme)", "Semena"),
(r"(food|crop|fruit|veg|hrana|pridelek)", "Hrana"),
(r"(resource|wood|plank|ore|gem|gold|surovina)", "Surovine"),
(r".*", "Ostalo")
]
# We skip 'animations' (already done) and 'DEMO/FAZA' folders (too complex to guess without breaking phases)
# But wait, user said "vse ostale mape". FAZA_1/teren should also be organized?
# Yes, ideally.
}
def organize_recursive(base_path, rules):
print(f"📂 Organizing in {base_path}...")
count = 0
# Get files in the immediate folder (not recursive, to avoid moving already sorted files)
try:
files = [f for f in os.listdir(base_path) if os.path.isfile(os.path.join(base_path, f))]
except FileNotFoundError:
return 0
for filename in files:
if not filename.lower().endswith(('.png', '.jpg', '.jpeg')):
continue
fname_lower = filename.lower()
target_sub = "Ostalo"
for pattern, folder in rules:
if re.search(pattern, fname_lower):
target_sub = folder
break
# Don't move 'Ostalo' if it implies staying in root?
# Actually user wants subfolders. So 'Ostalo' subfolder is fine.
dest_dir = os.path.join(base_path, target_sub)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
src = os.path.join(base_path, filename)
dst = os.path.join(dest_dir, filename)
try:
shutil.move(src, dst)
count += 1
except Exception as e:
print(f"Error {filename}: {e}")
return count
def main():
print("🚀 STARTING GLOBAL ORGANIZATION...")
# We need to find ALL occurrences of 'liki', 'teren', 'predmeti'
# even inside DEMO, FAZA_1 etc.
total_moved = 0
for root, dirs, files in os.walk(ROOT):
# Identify if current 'root' matches one of our targets
folder_name = os.path.basename(root)
if folder_name in CONFIG:
# Apply rules for this folder
total_moved += organize_recursive(root, CONFIG[folder_name])
# Optimization: Don't recurse into the folders we just created (Kai, Ana...)
# But os.walk creates the list 'dirs' upfront.
# We can modify 'dirs' in-place to prune.
# If we just organized 'liki', we created 'Kai', 'Ana'. We shouldn't process 'liki/Kai' as 'liki'.
# Since 'Kai' is not in CONFIG keys, it will be skipped automatically.
# Perfect.
print("="*40)
print(f"✅ GLOBAL ORGANIZATION COMPLETE. Moved {total_moved} files.")
print("="*40)
if __name__ == "__main__":
main()