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_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():
|
||||
if len(sys.argv) < 3:
|
||||
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_path = "src/input/"
|
||||
output_path = "src/output/"
|
||||
os.makedirs(output_path, exist_ok=True)
|
||||
if "-o" in sys.argv:
|
||||
o_index = sys.argv.index("-o")
|
||||
if o_index + 1 < len(sys.argv):
|
||||
@@ -31,7 +48,7 @@ def main():
|
||||
else:
|
||||
timestamp = time.strftime("%Y%m%d")
|
||||
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":
|
||||
generate_json_paloalto(input_data, output_file_json)
|
||||
@@ -55,7 +72,7 @@ def main():
|
||||
else:
|
||||
timestamp = time.strftime("%Y%m%d")
|
||||
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)
|
||||
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:
|
||||
timestamp = time.strftime("%Y%m%d")
|
||||
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)
|
||||
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file_json}\n - Excel: {excel_file}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user