From 66e3258d528eac4a2f256de3b86cf16eaecc75d1 Mon Sep 17 00:00:00 2001 From: Laurier Loiselle Date: Wed, 19 Apr 2023 17:23:40 -0400 Subject: [PATCH 1/3] templates: bom: show bom header --- src/wireviz/templates/bom.html | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wireviz/templates/bom.html b/src/wireviz/templates/bom.html index b019d57..22364fe 100644 --- a/src/wireviz/templates/bom.html +++ b/src/wireviz/templates/bom.html @@ -53,6 +53,7 @@
+ BOM {% if not bom_reversed %} {{ bom_header_gen() }} From 687e99d1a21eecacd8b0ba019f2f31c4a7f7737f Mon Sep 17 00:00:00 2001 From: Laurier Loiselle Date: Wed, 19 Apr 2023 17:28:26 -0400 Subject: [PATCH 2/3] wireviz: add index_table to titlepage --- src/wireviz/templates/index_table.html | 69 ++++++++++++++++++++++ src/wireviz/templates/titlepage.html | 4 ++ src/wireviz/wv_cli.py | 79 +++++++++++--------------- src/wireviz/wv_dataclasses.py | 1 + src/wireviz/wv_output.py | 63 ++++++++++++++++++++ 5 files changed, 169 insertions(+), 47 deletions(-) create mode 100644 src/wireviz/templates/index_table.html diff --git a/src/wireviz/templates/index_table.html b/src/wireviz/templates/index_table.html new file mode 100644 index 0000000..acf9734 --- /dev/null +++ b/src/wireviz/templates/index_table.html @@ -0,0 +1,69 @@ + + + + +{% macro index_table_header_gen() -%} + + {% for item in index_table_header %} + + {% endfor %} + +{%- endmacro %} + + +
+ INDEX TABLE +
{{ item }}
+ {{ index_table_header_gen() }} + + {% for row in index_table_content %} + + {% for item in row %} + + {% endfor %} + + {% endfor %} + +
{{ item }}
+
diff --git a/src/wireviz/templates/titlepage.html b/src/wireviz/templates/titlepage.html index 937ca19..415120a 100644 --- a/src/wireviz/templates/titlepage.html +++ b/src/wireviz/templates/titlepage.html @@ -14,4 +14,8 @@ {% if show_bom %} {{ bom }} {% endif %} + + {% if show_index_table %} + {{ index_table }} + {% endif %} {% endblock %} diff --git a/src/wireviz/wv_cli.py b/src/wireviz/wv_cli.py index 8f39d11..22656d7 100644 --- a/src/wireviz/wv_cli.py +++ b/src/wireviz/wv_cli.py @@ -14,8 +14,7 @@ import yaml import wireviz.wireviz as wv from wireviz import APP_NAME, __version__ -from wireviz.wv_bom import bom_list -from wireviz.wv_output import generate_pdf_output, generate_html_output, generate_shared_bom +from wireviz.wv_output import generate_pdf_output, generate_html_output, generate_shared_bom, generate_titlepage from wireviz.wv_dataclasses import AUTOGENERATED_PREFIX, Metadata, Options format_codes = { @@ -126,23 +125,29 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi # determine output formats output_formats = {format_codes[f] for f in formats if f in format_codes} harness_output_formats = output_formats.copy() - create_titlepage = False - # Only generate the global pdf if there's multiple files - if len(files) > 1 and 'pdf' in harness_output_formats: - harness_output_formats.remove('pdf') - create_titlepage = True - titlepage_path = (_output_dir / "titlepage").with_suffix(".html") - - harness = None shared_bom = {} - sheet_current = 1 - if create_titlepage: - sheet_current += 1 - output_names = [] + + extra_metadata = {} + extra_metadata["output_dir"] = _output_dir + extra_metadata["output_names"] = [] + extra_metadata["sheet_total"] = len(files) + extra_metadata["sheet_current"] = 1 + + # Only generate the global pdf if there's multiple files + create_titlepage = False + if extra_metadata["sheet_total"] > 1: + create_titlepage = True + extra_metadata["titlepage"] = Path("titlepage") + extra_metadata["sheet_current"] += 1 + extra_metadata["sheet_total"] += 1 + + if 'pdf' in harness_output_formats: + harness_output_formats.remove('pdf') + # run WireVIz on each input file for _file in files: _output_name = _file.stem if not output_name else output_name - output_names.append(_output_dir / _output_name) + extra_metadata["output_names"].append(_output_name) print("Input file: ", _file) print( @@ -150,13 +155,7 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi f"{_output_dir / _output_name}.[{'|'.join(output_formats)}]", ) - extra_metadata = {} extra_metadata["sheet_name"] = _output_name.upper() - extra_metadata["sheet_total"] = len(files) - if create_titlepage: - extra_metadata["sheet_total"] += 1 - extra_metadata["sheet_current"] = sheet_current - sheet_current += 1 file_dir = _file.parent @@ -171,6 +170,7 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi ) shared_bom = ret["shared_bom"] + shared_bom_base = None if "shared_bom" in output_formats: shared_bom_base, shared_bomlist = generate_shared_bom( @@ -181,37 +181,22 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi multiplier_file_name=multiplier_file_name, ) - # TODO: instead have a parse function that create a titlepage, not a harness if ('html' in output_formats) and create_titlepage: + # TODO: yaml data parsing shared yaml_data_str = "\n".join(f.open("r").read() for f in prepend) yaml_data = yaml.safe_load(yaml_data_str) - titlepage_metadata = { - **yaml_data.get("metadata", {}), - **extra_metadata, - "sheet_current": 1, - "sheet_name": "titlepage", - "output_name": "titlepage", - "bom_updated_position": "top: 20mm; left: 10mm", - "notes_width": "200mm", - } - titlepage_metadata['template']['name'] = 'titlepage' - titlepage_options = { - **yaml_data.get("options", {}), - "show_bom": True, - "show_notes": True, - } - generate_html_output( - titlepage_path, - bom = bom_list(shared_bom), - metadata = Metadata(**titlepage_metadata), # TBD what we need to add here - options = Options(**titlepage_options), - ) - if 'pdf' in output_formats and 'html' in output_formats and len(output_names) > 1: - if create_titlepage: - output_names.insert(0, titlepage_path) + generate_titlepage(yaml_data, extra_metadata, shared_bom) - generate_pdf_output(output_names) + if 'pdf' in output_formats: + extra_metadata["titlepage"] = extra_metadata["titlepage"].with_suffix('_for_pdf') + if create_titlepage: + extra_metadata["output_names"].insert(0, extra_metadata["titlepage"].with_suffix('.html')) + + generate_titlepage(yaml_data, extra_metadata, shared_bom, for_pdf=True) + + if 'pdf' in output_formats: + generate_pdf_output([_output_dir / p for p in extra_metadata["output_names"]]) print() # blank line after execution diff --git a/src/wireviz/wv_dataclasses.py b/src/wireviz/wv_dataclasses.py index 65278e0..a769e94 100644 --- a/src/wireviz/wv_dataclasses.py +++ b/src/wireviz/wv_dataclasses.py @@ -423,6 +423,7 @@ class BomEntry: class Options: fontname: PlainText = "arial" show_bom: bool = True + show_index_table: bool = False show_notes: bool = True notes_on_right: bool = True notes_width: str = "100mm" diff --git a/src/wireviz/wv_output.py b/src/wireviz/wv_output.py index 0218372..d40d789 100644 --- a/src/wireviz/wv_output.py +++ b/src/wireviz/wv_output.py @@ -156,6 +156,7 @@ def generate_html_output( "bgcolor": options.bgcolor.html, "show_bom": options.show_bom, "show_notes": options.show_notes, + "show_index_table": options.show_index_table, "notes_on_right": options.notes_on_right, "notes_width": options.notes_width, "diagram": svgdata, @@ -207,8 +208,70 @@ def generate_html_output( if "notes" in replacements: replacements["notes"] = get_template("notes.html").render(replacements) + # prepare index_table + replacements["index_table"] = get_template("index_table.html").render(replacements) + # generate page template page_rendered = get_template(template_name, ".html").render(replacements) # save generated file filename.with_suffix(".html").open("w").write(page_rendered) + +def generate_titlepage(yaml_data, extra_metadata, shared_bom, for_pdf=False): + print('Generating titlepage') + + index_table_content = [] + index_table_content.append(( + 1, extra_metadata['titlepage'], '' + )) + + for index, page_name in enumerate(extra_metadata['output_names']): + index_table_content.append(( + index+2, page_name, '' + )) + + + if not for_pdf: + index_table_content = [( + p[0], + f"{p[1]}", + p[2], + ) for p in index_table_content] + + + #if create_titlepage: + # extra_metadata["index_table_content"].append([ + # sheet_current, + # f"{extra_metadata['sheet_name']}", + # "", + # ]) + #index_table_content.insert(0, [ + # 1, + # f"Title Page", + # '' + #]) + + titlepage_metadata = { + **yaml_data.get("metadata", {}), + **extra_metadata, + "sheet_current": 1, + "sheet_name": "titlepage", + "output_name": "titlepage", + "index_table_header": ["Sheet", "Harness", "Notes"], + "index_table_content": index_table_content, + "bom_updated_position": "top: 20mm; left: 10mm", + "notes_width": "200mm", + } + titlepage_metadata['template']['name'] = 'titlepage' + titlepage_options = { + "show_bom": True, + "show_index_table": True, + "show_notes": True, + **yaml_data.get("options", {}), + } + generate_html_output( + extra_metadata['output_dir']/ extra_metadata['titlepage'], + bom = bom_list(shared_bom), + metadata = Metadata(**titlepage_metadata), # TBD what we need to add here + options = Options(**titlepage_options), + ) From 3ebb12c8a325345fa1a09942039a870a96ec40d2 Mon Sep 17 00:00:00 2001 From: Laurier Loiselle Date: Wed, 19 Apr 2023 17:31:57 -0400 Subject: [PATCH 3/3] tools: build_examples: simplify the tool, no git diff supported --- src/wireviz/tools/build_examples.py | 83 +++++------------------------ 1 file changed, 14 insertions(+), 69 deletions(-) diff --git a/src/wireviz/tools/build_examples.py b/src/wireviz/tools/build_examples.py index 0bc001c..575f8a4 100755 --- a/src/wireviz/tools/build_examples.py +++ b/src/wireviz/tools/build_examples.py @@ -63,23 +63,21 @@ def build_generated(groupkeys): with (path / readme).open("w") as out: out.write(f'# {groups[key]["title"]}\n\n') # collect and iterate input YAML files + yaml_files = [f for f in collect_filenames("Building", key, input_extensions)] + try: + res = cli([ + "--formats", "ghpstb", # no pdf for now + "--prepend", yaml_files[0].parent / "metadata.yml", + *[str(f) for f in yaml_files], + ]) + except BaseException as e: + if str(e) != "0" and not isinstance( + e, (click.ClickException, SystemExit) + ): + raise - for yaml_file in collect_filenames("Building", key, input_extensions): - try: - res = cli([ - "--formats", - "ghpstPb", - str(yaml_file), - "--prepend", - yaml_file.parent / "metadata.yml" - ]) - except BaseException as e: - if str(e) != "0" and not isinstance( - e, (click.ClickException, SystemExit) - ): - raise - - if build_readme: + if build_readme: + for yaml_file in yaml_files: i = "".join(filter(str.isdigit, yaml_file.stem)) with (path / readme).open("a") as out: @@ -113,42 +111,6 @@ def clean_generated(groupkeys): print(f' rm "{filename}"') filename.unlink() - -def compare_generated(groupkeys, branch="", include_graphviz_output=False): - if branch: - branch = f" {branch.strip()}" - compare_extensions = ( - generated_extensions - if include_graphviz_output - else extensions_not_containing_graphviz_output - ) - for key in groupkeys: - # collect and compare files - for filename in collect_filenames("Comparing", key, compare_extensions): - cmd = f'git --no-pager diff{branch} -- "{filename}"' - print(f" {cmd}") - os.system(cmd) - - -def restore_generated(groupkeys, branch=""): - if branch: - branch = f" {branch.strip()}" - for key in groupkeys: - # collect input YAML files - filename_list = collect_filenames("Restoring", key, input_extensions) - # collect files to restore - filename_list = [ - fn.with_suffix(ext) for fn in filename_list for ext in generated_extensions - ] - if readme in groups[key]: - filename_list.append(groups[key]["path"] / readme) - # restore files - for filename in filename_list: - cmd = f'git checkout{branch} -- "{filename}"' - print(f" {cmd}") - os.system(cmd) - - def parse_args(): parser = argparse.ArgumentParser( description=f"{APP_NAME} Example Manager", @@ -167,19 +129,6 @@ def parse_args(): default="build", help="what to do with the generated files (default: build)", ) - parser.add_argument( - "-c", - "--compare-graphviz-output", - action="store_true", - help="the Graphviz output is also compared (default: False)", - ) - parser.add_argument( - "-b", - "--branch", - action="store", - default="", - help="branch or commit to compare with or restore from", - ) parser.add_argument( "-g", "--groups", @@ -197,10 +146,6 @@ def main(): build_generated(args.groups) elif args.action == "clean": clean_generated(args.groups) - elif args.action == "compare" or args.action == "diff": - compare_generated(args.groups, args.branch, args.compare_graphviz_output) - elif args.action == "restore": - restore_generated(args.groups, args.branch) if __name__ == "__main__":