import os
import glob

# Ścieżka do katalogu projektu
project_path = os.path.dirname(os.path.abspath(__file__))

# Szukamy wszystkich katalogów "migrations" w aplikacjach
for root, dirs, files in os.walk(project_path):
    if "migrations" in dirs:
        migrations_path = os.path.join(root, "migrations")
        print(f"Checking: {migrations_path}")
        
        # Usuwamy wszystkie pliki migracji oprócz __init__.py
        for migration_file in glob.glob(os.path.join(migrations_path, "*.py")):
            if os.path.basename(migration_file) != "__init__.py":
                print(f"Removing: {migration_file}")
                os.remove(migration_file)
        
        # Usuwamy wszystkie pliki .pyc w katalogach migracji
        for pyc_file in glob.glob(os.path.join(migrations_path, "*.pyc")):
            print(f"Removing: {pyc_file}")
            os.remove(pyc_file)


import os
import glob
import shutil

# Ścieżka do katalogu projektu
project_path = os.path.dirname(os.path.abspath(__file__))

# Szukamy wszystkich katalogów "__pycache__" w projekcie
for root, dirs, files in os.walk(project_path):
    for dir_name in dirs:
        if dir_name == "__pycache__":
            pycache_path = os.path.join(root, dir_name)
            print(f"Removing cache folder: {pycache_path}")
            shutil.rmtree(pycache_path, ignore_errors=True)

# Szukamy wszystkich plików .pyc i .pyo w projekcie
for ext in ("*.pyc", "*.pyo"):
    for file_path in glob.glob(os.path.join(project_path, "**", ext), recursive=True):
        if os.path.isfile(file_path):
            print(f"Removing cache file: {file_path}")
            os.remove(file_path)

print("✅ Python cache cleared successfully.")
