Files

154 lines
4.1 KiB
Python
Raw Permalink Normal View History

2026-01-14 14:15:06 +01:00
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__))
2026-01-15 09:57:43 +01:00
VENV_DIR = os.path.join(BASE_DIR, ".venv")
2026-01-14 14:15:06 +01:00
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…")
2026-06-01 09:51:24 +02:00
script_path = os.path.abspath(__file__)
2026-01-14 14:15:06 +01:00
subprocess.check_call([
venv_python(),
2026-06-01 09:51:24 +02:00
script_path
2026-01-14 14:15:06 +01:00
])
sys.exit(0)
# Contenu fenêtre principale
def open_main_gui():
root = tk.Tk()
root.title("SCAN")
2026-06-01 09:51:24 +02:00
root.geometry("650x500")
2026-01-15 13:54:56 +01:00
root.resizable(True, True)
2026-01-14 14:15:06 +01:00
2026-06-01 09:51:24 +02:00
header_frame = tk.Frame(root)
header_frame.pack(fill="x", pady=10, padx=10)
logo_path = os.path.join(BASE_DIR, "Computacenter_logo.png")
if os.path.isfile(logo_path):
try:
logo_img = tk.PhotoImage(file=logo_path)
logo_img = logo_img.subsample(15, 15)
logo_label = tk.Label(header_frame, image=logo_img)
logo_label.image = logo_img
logo_label.pack(side="right")
except Exception as e:
print(f"[WARN] Impossible de charger le logo : {e}")
2026-01-14 14:15:06 +01:00
ttk.Label(
root,
text="Analyse Réseau",
font=("Arial", 16, "bold")
2026-06-01 09:51:24 +02:00
).pack(pady=(0, 20))
2026-01-14 14:15:06 +01:00
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" \
2026-06-01 09:51:24 +02:00
"\n + possibilité de générer une matrice de routage en Excel (route statique uniquement)" \
"\n + possibilité de générer un rapport des interfaces en Excel",
2026-01-14 14:15:06 +01:00
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)" \
2026-05-20 13:56:08 +02:00
"\n + possibilité de générer un schéma réseau" \
"\n + possibilité de générer un rapport des liens inter-switches en Excel" \
"\n + possibilité de générer un rapport des stack en Excel" \
"\n + possibilité de générer un rapport des interfaces en Excel",
2026-01-14 14:15:06 +01:00
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()