venv + install requirement auto
This commit is contained in:
@@ -1,31 +1,10 @@
|
|||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk, filedialog, messagebox
|
from tkinter import ttk, filedialog, messagebox
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Chemin
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
FIREWALL_DIR = os.path.join(
|
|
||||||
BASE_DIR,
|
|
||||||
"Parseurs_config_Firewall"
|
|
||||||
)
|
|
||||||
|
|
||||||
FIREWALL_MAIN = os.path.join(
|
|
||||||
FIREWALL_DIR,
|
|
||||||
"src",
|
|
||||||
"main.py"
|
|
||||||
)
|
|
||||||
|
|
||||||
HELP_FILE_FW = os.path.join(BASE_DIR, "help_Firewall.md")
|
|
||||||
|
|
||||||
OUTPUT_DIR = os.path.join(FIREWALL_DIR, "src", "output")
|
|
||||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
||||||
|
|
||||||
PYTHON_EXEC = sys.executable
|
|
||||||
|
|
||||||
class ToolTip:
|
class ToolTip:
|
||||||
def __init__(self, widget, text):
|
def __init__(self, widget, text):
|
||||||
@@ -65,21 +44,24 @@ class ToolTip:
|
|||||||
self.tipwindow.destroy()
|
self.tipwindow.destroy()
|
||||||
self.tipwindow = None
|
self.tipwindow = None
|
||||||
|
|
||||||
# Fenêtre principale
|
# Contenu fenêtre Analyse Firewall
|
||||||
root = tk.Tk()
|
def open_firewall_gui(root, BASE_DIR):
|
||||||
root.title("Analyse Réseau")
|
FIREWALL_DIR = os.path.join(
|
||||||
root.geometry("650x350")
|
BASE_DIR,
|
||||||
root.resizable(False, False)
|
"Parseurs_config_Firewall"
|
||||||
|
|
||||||
|
|
||||||
def open_switch_gui():
|
|
||||||
messagebox.showinfo(
|
|
||||||
"Analyse log Switch",
|
|
||||||
"L'analyse log switch n'est pas encore disponible."
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fenêtre Firewall
|
FIREWALL_MAIN = os.path.join(
|
||||||
def open_firewall_gui():
|
FIREWALL_DIR,
|
||||||
|
"src",
|
||||||
|
"main.py"
|
||||||
|
)
|
||||||
|
|
||||||
|
HELP_FILE_FW = os.path.join(BASE_DIR, "help_Firewall.md")
|
||||||
|
|
||||||
|
OUTPUT_DIR = os.path.join(FIREWALL_DIR, "src", "output")
|
||||||
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||||
|
|
||||||
app = tk.Toplevel(root)
|
app = tk.Toplevel(root)
|
||||||
app.title("Analyse Configuration Firewall")
|
app.title("Analyse Configuration Firewall")
|
||||||
app.geometry("800x400")
|
app.geometry("800x400")
|
||||||
@@ -171,7 +153,7 @@ def open_firewall_gui():
|
|||||||
app.update_idletasks()
|
app.update_idletasks()
|
||||||
def process():
|
def process():
|
||||||
cmd = [
|
cmd = [
|
||||||
PYTHON_EXEC,
|
sys.executable,
|
||||||
FIREWALL_MAIN,
|
FIREWALL_MAIN,
|
||||||
firewall_var.get(),
|
firewall_var.get(),
|
||||||
input_var.get()
|
input_var.get()
|
||||||
@@ -316,54 +298,4 @@ def open_firewall_gui():
|
|||||||
command=run_parser
|
command=run_parser
|
||||||
).pack(pady=15)
|
).pack(pady=15)
|
||||||
|
|
||||||
app.mainloop()
|
app.mainloop()
|
||||||
|
|
||||||
# Contenu fenêtre principale
|
|
||||||
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=open_firewall_gui
|
|
||||||
).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=open_switch_gui
|
|
||||||
).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()
|
|
||||||
9
gui_switch.py
Normal file
9
gui_switch.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from tkinter import ttk, filedialog, messagebox
|
||||||
|
|
||||||
|
# Contenu fenêtre Analyse Switch
|
||||||
|
def open_switch_gui(root, BASE_DIR):
|
||||||
|
messagebox.showinfo(
|
||||||
|
"Analyse log Switch",
|
||||||
|
"L'analyse log switch n'est pas encore disponible."
|
||||||
|
)
|
||||||
@@ -10,12 +10,10 @@ Il founit également la possibilité de générer une **matrice de routage au fo
|
|||||||
## Utilisation
|
## Utilisation
|
||||||
|
|
||||||
### Pré-requis
|
### Pré-requis
|
||||||
```bash
|
|
||||||
cd .\Parseurs_config_Firewall\
|
|
||||||
python -m venv .venv
|
|
||||||
.\.venv\Scripts\activate
|
|
||||||
|
|
||||||
pip install -r .\Parseurs_config_Firewall\src\requirements.txt
|
|
||||||
```
|
|
||||||
- Mettre le/les fichier(s) et/ou dossier(s) de configurations dans le dossier `/Parseurs_config_Firewall/src/input/`
|
- Mettre le/les fichier(s) et/ou dossier(s) de configurations dans le dossier `/Parseurs_config_Firewall/src/input/`
|
||||||
- Modifier le fichier `site.json` de données dans `/Parseurs_config_Firewall/src/data/`
|
- Modifier le fichier `site.json` de données dans `/Parseurs_config_Firewall/src/data/`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 ./main.py
|
||||||
|
```
|
||||||
|
|||||||
0
help_Switch.md
Normal file
0
help_Switch.md
Normal file
133
main.py
Normal file
133
main.py
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
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(False, False)
|
||||||
|
|
||||||
|
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()
|
||||||
Reference in New Issue
Block a user