Files
novafarma/scripts/utils/organize_cleanup.py

105 lines
3.2 KiB
Python

import os
import shutil
import glob
REPO_ROOT = "/Users/davidkotnik/repos/novafarma"
DESKTOP_SOURCE = "/Users/davidkotnik/Desktop/referencne slike 2"
# 1. DELETE LIST (Old backups, trash, clutter directories)
DIRS_TO_DELETE = [
"_BACKUP_OLD_IMAGES_20260125_121156",
"_TRASH_BIN",
"DEBUG_TOTAL_RECOVERY",
"EMERGENCY_SYSTEMS_RECOVERY",
"INTRO_STORY_IMAGES",
"MASTER_DESIGN_RECOVERY",
"MASTER_RECOVERY",
"NOVE_SLIKE",
"gcloud auth application-default login", # Looks like a mistake folder
"logs",
"old_logic" # Assumption: User wants chaos gone.
]
FILES_TO_DELETE = [
"rename_execution_log.txt",
"rename_map.json",
"rename_statistics.json",
"image_inventory.json",
".DS_Store"
]
# 2. ORGANIZE (Target Folder -> List of extensions or specific files)
ORGANIZATION_MAP = {
"web": [".html"],
"docs": [".md"], # Excluding README.md and DEV_LOG.md (handled manually)
"scripts/utils": [".py"],
"config": [".json", ".code-workspace", ".gitignore"]
}
# PROTECTED FILES (Do not move these even if they match extensions)
PROTECTED = [
"README.md",
"DEV_LOG.md",
"package.json",
"package-lock.json",
"organize_cleanup.py" # Self
]
def cleanup_and_organize():
print("--- STARTING CLEANUP ---")
# 1. DELETE
for dir_name in DIRS_TO_DELETE:
path = os.path.join(REPO_ROOT, dir_name)
if os.path.exists(path):
print(f"Deleting directory: {dir_name}")
shutil.rmtree(path)
for file_name in FILES_TO_DELETE:
path = os.path.join(REPO_ROOT, file_name)
if os.path.exists(path):
print(f"Deleting file: {file_name}")
os.remove(path)
# 2. ORGANIZE Root Files
print("\n--- ORGANIZING ROOT ---")
files_in_root = [f for f in os.listdir(REPO_ROOT) if os.path.isfile(os.path.join(REPO_ROOT, f))]
for file_cat, extensions in ORGANIZATION_MAP.items():
target_dir = os.path.join(REPO_ROOT, file_cat)
if not os.path.exists(target_dir):
os.makedirs(target_dir)
for file in files_in_root:
if file in PROTECTED:
continue
_, ext = os.path.splitext(file)
if ext in extensions or file in extensions: # Handle specific filenames in list
src = os.path.join(REPO_ROOT, file)
dst = os.path.join(target_dir, file)
print(f"Moving {file} -> {file_cat}/")
shutil.move(src, dst)
# 3. REFRESH ASSETS
print("\n--- REFRESHING ASSETS ---")
assets_dir = os.path.join(REPO_ROOT, "assets")
# Ensure assets exists
if not os.path.exists(assets_dir):
os.makedirs(assets_dir)
print("Replacing assets with fresh copies from Desktop...")
# Copy from desktop
for file in os.listdir(DESKTOP_SOURCE):
if file.lower().endswith(('.jpg', '.png', '.jpeg')):
src = os.path.join(DESKTOP_SOURCE, file)
dst = os.path.join(assets_dir, file)
shutil.copy2(src, dst)
print("Assets updated.")
print("\nSUCCESS: Repository cleaned and organized.")
if __name__ == "__main__":
cleanup_and_organize()