36 lines
943 B
Python
36 lines
943 B
Python
# main.py
|
|
from pathlib import Path
|
|
from utils.texttools import split_display_sections
|
|
from models.hpe5130 import SwitchHPE5130
|
|
from output.export_json import export_switch_to_json
|
|
|
|
|
|
|
|
def read_file_with_fallback(path: Path) -> str:
|
|
try:
|
|
return path.read_text(encoding="utf-8")
|
|
except UnicodeDecodeError:
|
|
print("[warn] UTF-8 échoué, tentative avec cp1252...")
|
|
return path.read_text(encoding="cp1252")
|
|
|
|
|
|
def main():
|
|
log_path = Path("data/example.log")
|
|
if not log_path.exists():
|
|
print(f"Fichier non trouvé : {log_path}")
|
|
return
|
|
|
|
content = read_file_with_fallback(log_path)
|
|
sections = split_display_sections(content)
|
|
|
|
switch = SwitchHPE5130()
|
|
for section in sections:
|
|
switch.parse_block(section["section"], section["content"])
|
|
|
|
output_path = Path("data/switch_parsed.json")
|
|
export_switch_to_json(switch, output_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|