Skip to content

Commit

Permalink
Refactor code and improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Tes3awy committed May 10, 2022
1 parent de2f52a commit 6fbc38b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions parse_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

parser = ArgumentParser(
prog="parse Excel",
usage="python parse_excel.py --file <path to an Excel file>",
usage="python parse_excel.py --file path/to/excel/file",
description="An Excel file that contains subnets",
epilog="Enjoy the program! :)",
allow_abbrev=True,
Expand All @@ -23,12 +23,14 @@
action="store",
type=str,
required=True,
help="the path to an Excel file",
help="Path to an Excel file",
)

args = parser.parse_args()

try:
svi_generator(excel_file=args.file)
f = svi_generator(excel_file=args.file)
except (FileNotFoundError, PermissionError) as e:
raise SystemExit(print(f"[red]{e}")) from e
else:
print(f"\n[green]Created {f.name} in cwd", end="\n\n")
8 changes: 4 additions & 4 deletions svi_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def svi_generator(excel_file: str) -> None:
svi_cfg = template.render(vlans=vlans)

# Export the template result to a text file
cfg_fname = f'{excel_file.replace(".xlsx", "")}_svi.txt'
with open(file=cfg_fname, mode="wt", encoding="utf-8") as cfg_file:
cfg_file.write(svi_cfg)
cfg_fname = f'{excel_file.replace(".xlsx", "")}_SVI-template.txt'
with open(file=cfg_fname, mode="wt+", encoding="utf-8") as f:
f.write(svi_cfg)

print(f"\n[green]Created {cfg_fname}", end="\n\n")
return f

0 comments on commit 6fbc38b

Please sign in to comment.