71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
def main():
|
|
base = Path(r"c:\Users\Pars\Desktop\saba-python\secure_sms")
|
|
|
|
print("[1/3] Creating Architectural Directories...")
|
|
for folder in ['core', 'application', 'infrastructure', 'ui']:
|
|
(base / folder).mkdir(exist_ok=True)
|
|
(base / folder / '__init__.py').touch(exist_ok=True)
|
|
|
|
print("[2/3] Moving Domain Logic Files...")
|
|
moves = {
|
|
'models.py': 'core',
|
|
'protocol.py': 'core',
|
|
'security.py': 'core',
|
|
'services.py': 'application',
|
|
'controller.py': 'application',
|
|
'database.py': 'infrastructure',
|
|
'gsm.py': 'infrastructure'
|
|
}
|
|
|
|
for file_name, folder in moves.items():
|
|
src = base / file_name
|
|
dst = base / folder / file_name
|
|
if src.exists():
|
|
shutil.move(str(src), str(dst))
|
|
print(f' -> Moved {file_name} to {folder}/')
|
|
|
|
print("[3/3] Refactoring Import Statements...")
|
|
replacements = {
|
|
'from secure_sms.infrastructure.database': 'from secure_sms.infrastructure.database',
|
|
'from secure_sms.infrastructure.gsm': 'from secure_sms.infrastructure.gsm',
|
|
'from secure_sms.application.services': 'from secure_sms.application.services',
|
|
'from secure_sms.application.controller': 'from secure_sms.application.controller',
|
|
'from secure_sms.core.models': 'from secure_sms.core.models',
|
|
'from secure_sms.core.protocol': 'from secure_sms.core.protocol',
|
|
'from secure_sms.core.security': 'from secure_sms.core.security',
|
|
'import secure_sms.infrastructure.database': 'import secure_sms.infrastructure.database'
|
|
}
|
|
|
|
project_root = Path(r"c:\Users\Pars\Desktop\saba-python")
|
|
for py_file in project_root.rglob('*.py'):
|
|
if py_file.name == '.venv' or '.runtime-venv' in str(py_file):
|
|
continue
|
|
try:
|
|
content = py_file.read_text(encoding='utf-8')
|
|
orig = content
|
|
for old, new in replacements.items():
|
|
content = content.replace(old, new)
|
|
if content != orig:
|
|
py_file.write_text(content, encoding='utf-8')
|
|
print(f' -> Updated imports in {py_file.name}')
|
|
except Exception as e:
|
|
pass
|
|
|
|
# Cleanup obsolete root files
|
|
print("[Cleanup] Removing Legacy Files...")
|
|
legacy = ["App_GUI.py", "Crypto_Engine.py", "DB_Handler.py", "GSM_Manager.py"]
|
|
for legacy_file in legacy:
|
|
f = project_root / legacy_file
|
|
if f.exists():
|
|
f.unlink()
|
|
print(f' -> Deleted {legacy_file}')
|
|
|
|
print("\n✅ Migration complete! Backend is now strictly adhering to Clean Architecture.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|