Files
Analyse_Reseaux/main.py
2026-01-15 13:54:56 +01:00

133 lines
3.2 KiB
Python

import subprocess
import os
import sys
import venv
import tkinter as tk
from tkinter import ttk
from gui_firewall import open_firewall_gui
from gui_switch import open_switch_gui
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
VENV_DIR = os.path.join(BASE_DIR, ".venv")
REQ_FILE = os.path.join(BASE_DIR, "requirements.txt")
def venv_python():
if sys.platform == "win32":
return os.path.join(VENV_DIR, "Scripts", "python.exe")
return os.path.join(VENV_DIR, "bin", "python")
def in_venv():
return sys.prefix != sys.base_prefix
def create_venv():
print("[INFO] Création de l'environnement virtuel…")
venv.EnvBuilder(with_pip=True).create(VENV_DIR)
def install_requirements():
print("[INFO] Vérification / installation des dépendances…")
subprocess.check_call([
venv_python(),
"-m",
"pip",
"install",
"--upgrade",
"pip",
"setuptools",
"wheel"
])
subprocess.check_call([
venv_python(),
"-m",
"pip",
"install",
"-r",
REQ_FILE
])
def bootstrap_venv():
if not os.path.isdir(VENV_DIR):
print("[INFO] Aucun venv détecté")
create_venv()
install_requirements()
return
print("[INFO] Environnement virtuel détecté")
install_requirements()
def relaunch_in_venv():
print("[INFO] Relance du script dans le venv…")
subprocess.check_call([
venv_python(),
__file__
])
sys.exit(0)
# Contenu fenêtre principale
def open_main_gui():
root = tk.Tk()
root.title("Analyse Réseau")
root.geometry("650x350")
root.resizable(True, True)
ttk.Label(
root,
text="Analyse Réseau",
font=("Arial", 16, "bold")
).pack(pady=20)
ttk.Label(
root,
text="Sélectionnez le type d'analyse à effectuer :",
font=("Arial", 11)
).pack(pady=10)
ttk.Button(
root,
text="Analyse configuration Firewall",
width=30,
command=lambda: open_firewall_gui(root, BASE_DIR)
).pack(pady=5)
ttk.Label(
root,
text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \
"\n + possibilité de générer une matrice de flux en Excel" \
"\n + possibilité de générer une matrice de routage en Excel (route statique uniquement)",
font=("Arial", 9, "italic"),
anchor="center",
justify="center"
).pack(pady=5)
ttk.Separator(root, orient="horizontal").pack(fill="x", pady=10)
ttk.Button(
root,
text="Analyse log Switch",
width=30,
command=lambda: open_switch_gui(root, BASE_DIR)
).pack(pady=5)
ttk.Label(
root,
text="(Convertir les données au format normalisé Yang dans un fichier JSON)" \
"\n + possibilité de générer un schéma réseau",
font=("Arial", 9, "italic"),
anchor="center",
justify="center"
).pack(pady=5)
root.mainloop()
def main():
if not in_venv():
bootstrap_venv()
relaunch_in_venv()
print("[INFO] Environnement prêt")
open_main_gui()
if __name__ == "__main__":
main()