import os import subprocess print("Konteyner icine dogrudan yama yapiliyor (Yol duzeltmesi)...") dirs = ["/opt/envanter_genel_vem", "/opt/envanter_9898"] python_patch = """ import re path = '/app/app/templates/admin/kpi_data_entry.html' try: with open(path, 'r', encoding='utf-8') as f: html = f.read() html = re.sub(r'\{%\s*if\s*not\s*is_unlocked\s*and\s*active_dept\s*%\}', r'{% if not is_unlocked and active_dept and active_dept.kpi_password %}', html) html = re.sub(r'\{%\s*if\s*is_unlocked\s*%\}', r'{% if is_unlocked or (active_dept and not active_dept.kpi_password) %}', html) with open(path, 'w', encoding='utf-8') as f: f.write(html) print("HTML yamalandi.") except Exception as e: print("HTML yama hatasi:", e) path2 = '/app/app/routes/admin.py' try: with open(path2, 'r', encoding='utf-8') as f: py_code = f.read() py_code = re.sub(r"elif\s+action\s*==\s*'save'\s+and\s+is_unlocked:", r"elif action == 'save' and (is_unlocked or (active_dept and not active_dept.kpi_password)):", py_code) with open(path2, 'w', encoding='utf-8') as f: f.write(py_code) print("Python yamalandi.") except Exception as e: print("Python yama hatasi:", e) """ patch_file = os.path.abspath("patch_inside.py") with open(patch_file, "w") as f: f.write(python_patch) for d in dirs: if os.path.exists(d): print(f"[{d}] Konteyner icine yama uygulaniyor...") subprocess.run(f"docker compose cp {patch_file} web:/app/patch_inside.py", shell=True, cwd=d) subprocess.run("docker compose exec -T web python3 /app/patch_inside.py", shell=True, cwd=d) subprocess.run("docker compose restart web", shell=True, cwd=d) print(f"[{d}] Konteyner basariyla yeniden baslatildi.") print("\nISLEM TAMAM! Lutfen sayfayi CTRL+F5 ile yenileyin.")