src: wireviz: support sheet count

This commit is contained in:
Laurier Loiselle 2023-01-20 17:26:02 -05:00
parent 55da28d1a9
commit a9329a4a4b
No known key found for this signature in database
GPG Key ID: 345920CC72089A3F
2 changed files with 18 additions and 2 deletions

View File

@ -119,6 +119,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
else: else:
prepend_input = "" prepend_input = ""
sheet_current = 1
# run WireVIz on each input file # run WireVIz on each input file
for file in filepaths: for file in filepaths:
file = Path(file) file = Path(file)
@ -127,6 +128,13 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
if not file.is_file(): if not file.is_file():
raise Exception(f"Path is not a file:\n{file}") raise Exception(f"Path is not a file:\n{file}")
extra_metadata = {}
extra_metadata['name'] = file.stem
extra_metadata['sheet_total'] = len(filepaths)
extra_metadata['sheet_current'] = sheet_current
sheet_current +=1
# file_out = file.with_suffix("") if not output_file else output_file # file_out = file.with_suffix("") if not output_file else output_file
_output_dir = file.parent if not output_dir else output_dir _output_dir = file.parent if not output_dir else output_dir
_output_name = file.stem if not output_name else output_name _output_name = file.stem if not output_name else output_name
@ -150,6 +158,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
output_dir=_output_dir, output_dir=_output_dir,
output_name=_output_name, output_name=_output_name,
image_paths=list(image_paths), image_paths=list(image_paths),
extra_metadata=extra_metadata,
) )
print() # blank line after execution print() # blank line after execution

View File

@ -121,6 +121,13 @@ def generate_html_output(
+ "</table>\n" + "</table>\n"
) )
if metadata:
sheet_current = metadata['sheet_current']
sheet_total = metadata['sheet_total']
else:
sheet_current = 1
sheet_total = 1
# prepare simple replacements # prepare simple replacements
replacements = { replacements = {
"<!-- %generator% -->": f"{APP_NAME} {__version__} - {APP_URL}", "<!-- %generator% -->": f"{APP_NAME} {__version__} - {APP_URL}",
@ -129,8 +136,8 @@ def generate_html_output(
"<!-- %diagram% -->": svgdata, "<!-- %diagram% -->": svgdata,
"<!-- %bom% -->": bom_html, "<!-- %bom% -->": bom_html,
"<!-- %bom_reversed% -->": bom_html_reversed, "<!-- %bom_reversed% -->": bom_html_reversed,
"<!-- %sheet_current% -->": "1", # TODO: handle multi-page documents "<!-- %sheet_current% -->": sheet_current,
"<!-- %sheet_total% -->": "1", # TODO: handle multi-page documents "<!-- %sheet_total% -->": sheet_total,
} }
# prepare metadata replacements # prepare metadata replacements