correction output file name
This commit is contained in:
@@ -7,6 +7,22 @@ from scripts.json_Forcepoint import generate_json_forcepoint
|
|||||||
from scripts.export_matrice_flux import export_to_excel as export_flux_to_excel
|
from scripts.export_matrice_flux import export_to_excel as export_flux_to_excel
|
||||||
from scripts.export_matrice_routage import export_to_excel as export_routing_to_excel
|
from scripts.export_matrice_routage import export_to_excel as export_routing_to_excel
|
||||||
|
|
||||||
|
def verify_if_file_exists(name):
|
||||||
|
print("AAAAAAAAAAAAAAAAA")
|
||||||
|
print(name)
|
||||||
|
base, ext = os.path.splitext(name)
|
||||||
|
counter = 1
|
||||||
|
print("BBBBBBBBBBBBBBB")
|
||||||
|
print(base)
|
||||||
|
new_name = name
|
||||||
|
print("CCCCCCCCCCCCCCC")
|
||||||
|
print(new_name)
|
||||||
|
while os.path.exists(new_name):
|
||||||
|
new_name = f"{base}_{counter}{ext}"
|
||||||
|
counter += 1
|
||||||
|
return new_name
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Usage: python3 src/main.py <firewall_type>[paloalto|stormshield|forcepoint] <input_directory/file> [-o <output_file>] [-f] [-r]")
|
print("Usage: python3 src/main.py <firewall_type>[paloalto|stormshield|forcepoint] <input_directory/file> [-o <output_file>] [-f] [-r]")
|
||||||
@@ -21,6 +37,7 @@ def main():
|
|||||||
input_data = sys.argv[2]
|
input_data = sys.argv[2]
|
||||||
input_path = "src/input/"
|
input_path = "src/input/"
|
||||||
output_path = "src/output/"
|
output_path = "src/output/"
|
||||||
|
os.makedirs(output_path, exist_ok=True)
|
||||||
if "-o" in sys.argv:
|
if "-o" in sys.argv:
|
||||||
o_index = sys.argv.index("-o")
|
o_index = sys.argv.index("-o")
|
||||||
if o_index + 1 < len(sys.argv):
|
if o_index + 1 < len(sys.argv):
|
||||||
@@ -31,7 +48,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
timestamp = time.strftime("%Y%m%d")
|
timestamp = time.strftime("%Y%m%d")
|
||||||
output_file_json = f"{output_path}{firewall_type}_{timestamp}.json"
|
output_file_json = f"{output_path}{firewall_type}_{timestamp}.json"
|
||||||
os.makedirs(output_path, exist_ok=True)
|
output_file_json = verify_if_file_exists(output_file_json)
|
||||||
|
|
||||||
if firewall_type == "paloalto":
|
if firewall_type == "paloalto":
|
||||||
generate_json_paloalto(input_data, output_file_json)
|
generate_json_paloalto(input_data, output_file_json)
|
||||||
@@ -55,7 +72,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
timestamp = time.strftime("%Y%m%d")
|
timestamp = time.strftime("%Y%m%d")
|
||||||
output_file_excel = f"{output_path}matrice_flux_{firewall_type}_{timestamp}.xlsx"
|
output_file_excel = f"{output_path}matrice_flux_{firewall_type}_{timestamp}.xlsx"
|
||||||
|
output_file_excel = verify_if_file_exists(output_file_excel)
|
||||||
excel_file = export_flux_to_excel(output_file_json, output_file_excel)
|
excel_file = export_flux_to_excel(output_file_json, output_file_excel)
|
||||||
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file_json}\n - Excel: {excel_file}")
|
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file_json}\n - Excel: {excel_file}")
|
||||||
|
|
||||||
@@ -71,7 +88,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
timestamp = time.strftime("%Y%m%d")
|
timestamp = time.strftime("%Y%m%d")
|
||||||
output_file_excel = f"{output_path}matrice_routage_{firewall_type}_{timestamp}.xlsx"
|
output_file_excel = f"{output_path}matrice_routage_{firewall_type}_{timestamp}.xlsx"
|
||||||
|
output_file_excel = verify_if_file_exists(output_file_excel)
|
||||||
excel_file = export_routing_to_excel(output_file_json, output_file_excel)
|
excel_file = export_routing_to_excel(output_file_json, output_file_excel)
|
||||||
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file_json}\n - Excel: {excel_file}")
|
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file_json}\n - Excel: {excel_file}")
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ def open_firewall_gui_multi(app, OUTPUT_DIR, HELP_FILE_FW, FIREWALL_DIR, FIREWAL
|
|||||||
app2 = tk.Toplevel(app)
|
app2 = tk.Toplevel(app)
|
||||||
app2.title("Analyse Configuration Firewall - Plusieurs firewall")
|
app2.title("Analyse Configuration Firewall - Plusieurs firewall")
|
||||||
app2.geometry("800x450")
|
app2.geometry("800x450")
|
||||||
app2.resizable(False, False)
|
app2.resizable(True, True)
|
||||||
|
|
||||||
matrice_flux = tk.BooleanVar()
|
matrice_flux = tk.BooleanVar()
|
||||||
matrice_routage = tk.BooleanVar()
|
matrice_routage = tk.BooleanVar()
|
||||||
@@ -159,6 +159,13 @@ def open_firewall_gui_multi(app, OUTPUT_DIR, HELP_FILE_FW, FIREWALL_DIR, FIREWAL
|
|||||||
if matrice_routage.get():
|
if matrice_routage.get():
|
||||||
cmd.append("-r")
|
cmd.append("-r")
|
||||||
|
|
||||||
|
cmd.append("-o")
|
||||||
|
if item["type"] == "file":
|
||||||
|
base_name = os.path.splitext(item["name"])[0]
|
||||||
|
cmd.append(base_name)
|
||||||
|
else:
|
||||||
|
cmd.append(item["name"])
|
||||||
|
|
||||||
print("Commande exécutée :", " ".join(cmd))
|
print("Commande exécutée :", " ".join(cmd))
|
||||||
subprocess.run(cmd, cwd=FIREWALL_DIR, check=True)
|
subprocess.run(cmd, cwd=FIREWALL_DIR, check=True)
|
||||||
|
|
||||||
@@ -412,7 +419,7 @@ def open_firewall_gui(root, BASE_DIR):
|
|||||||
app = tk.Toplevel(root)
|
app = tk.Toplevel(root)
|
||||||
app.title("Analyse Configuration Firewall")
|
app.title("Analyse Configuration Firewall")
|
||||||
app.geometry("800x450")
|
app.geometry("800x450")
|
||||||
app.resizable(False, False)
|
app.resizable(True, True)
|
||||||
|
|
||||||
firewall_var = tk.StringVar()
|
firewall_var = tk.StringVar()
|
||||||
input_var = tk.StringVar()
|
input_var = tk.StringVar()
|
||||||
|
|||||||
Reference in New Issue
Block a user