()
| 63 | subprocess.run([str(py_path), "-m", "playwright", "install", "chromium"], check=True) |
| 64 | |
| 65 | def setup_env(): |
| 66 | script_path = Path(__file__).resolve() |
| 67 | venv_path = script_path.parent / ".venv" |
| 68 | py = _venv_python_path(venv_path) |
| 69 | |
| 70 | current_venv = os.environ.get("VIRTUAL_ENV", "") |
| 71 | try: |
| 72 | if Path(sys.executable).resolve() == py.resolve(): |
| 73 | return |
| 74 | except Exception: |
| 75 | pass |
| 76 | if current_venv: |
| 77 | try: |
| 78 | if ( |
| 79 | Path(current_venv).resolve() == venv_path.resolve() and |
| 80 | Path(sys.executable).resolve() == py.resolve() |
| 81 | ): |
| 82 | return |
| 83 | except Exception: |
| 84 | pass |
| 85 | |
| 86 | required_pkgs = [ |
| 87 | "flask", "requests", "phonenumbers", "telethon", "fpdf2", "bs4", |
| 88 | "dnspython", "python-whois", "lxml", "pycountry", "playwright", "greenlet", |
| 89 | "holehe", "ignorant", "trio", "httpx", "h2", "opencv-python-headless", "numpy", |
| 90 | "exifread", "imageio-ffmpeg", "cryptography" |
| 91 | ] |
| 92 | |
| 93 | if not venv_path.exists(): |
| 94 | print("[*] Init CSCORZA IntelOSINT v.1...") |
| 95 | try: |
| 96 | py = _create_venv(venv_path, required_pkgs) |
| 97 | _sync_venv_packages(py, required_pkgs) |
| 98 | print("[*] Setup completato con successo!") |
| 99 | except Exception as e: |
| 100 | print(f"[!] Setup Error: {e}") |
| 101 | raise RuntimeError("Setup venv fallito") from e |
| 102 | else: |
| 103 | try: |
| 104 | if not _venv_is_healthy(venv_path): |
| 105 | print("[*] Ambiente virtuale non valido o collegato a un Python non piu disponibile. Ricreo la venv...") |
| 106 | shutil.rmtree(venv_path, ignore_errors=True) |
| 107 | py = _create_venv(venv_path, required_pkgs) |
| 108 | _sync_venv_packages(py, required_pkgs) |
| 109 | except Exception as e: |
| 110 | print(f"[!] Setup deps error: {e}") |
| 111 | raise RuntimeError("Allineamento dipendenze venv fallito") from e |
| 112 | |
| 113 | try: |
| 114 | env = os.environ.copy() |
| 115 | env["INTELOSINT_VENV_BOOTSTRAPPED"] = "1" |
| 116 | rc = subprocess.call([str(py), str(script_path)], env=env, cwd=str(script_path.parent)) |
| 117 | sys.exit(rc) |
| 118 | except OSError as e: |
| 119 | print(f"[!] Impossibile riavviare con la venv: {e}") |
| 120 | raise |
| 121 | |
| 122 | if __name__ == "__main__" and os.environ.get("INTELOSINT_VENV_BOOTSTRAPPED") != "1": |
no test coverage detected