From 07a6360c16bc5f104f5e74fd0a135cdcfceef7da Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:25:58 +0200 Subject: [PATCH] Rename `HDR_*` to `HEADER_*`, fix missing `P/N` string in output --- src/wireviz/Harness.py | 15 ++++++++------- src/wireviz/wv_bom.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index cbab7b5..bb7c329 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -15,7 +15,8 @@ from wireviz.wv_colors import get_color_hex, translate_color from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \ html_caption, remove_links, html_line_breaks from wireviz.wv_bom import pn_info_string, component_table_entry, \ - get_additional_component_table, bom_list, generate_bom + get_additional_component_table, bom_list, generate_bom, \ + HEADER_MPN, HEADER_SPN from wireviz.wv_html import generate_html_output from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \ open_file_read, open_file_write @@ -125,8 +126,8 @@ class Harness: rows = [[remove_links(connector.name) if connector.show_name else None], [f'P/N: {remove_links(connector.pn)}' if connector.pn else None, - html_line_breaks(pn_info_string(HDR_MPN, connector.manufacturer, connector.mpn)), - html_line_breaks(pn_info_string(HDR_SPN, connector.supplier, connector.spn))], + html_line_breaks(pn_info_string(HEADER_MPN, connector.manufacturer, connector.mpn)), + html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))], [html_line_breaks(connector.type), html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, @@ -209,10 +210,10 @@ class Harness: rows = [[remove_links(cable.name) if cable.show_name else None], [f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None, - html_line_breaks(pn_info_string(HDR_MPN, + html_line_breaks(pn_info_string(HEADER_MPN, cable.manufacturer if not isinstance(cable.manufacturer, list) else None, cable.mpn if not isinstance(cable.mpn, list) else None)), - html_line_breaks(pn_info_string(HDR_SPN, + html_line_breaks(pn_info_string(HEADER_SPN, cable.supplier if not isinstance(cable.supplier, list) else None, cable.spn if not isinstance(cable.spn, list) else None))], [html_line_breaks(cable.type), @@ -267,10 +268,10 @@ class Harness: wireidentification = [] if isinstance(cable.pn, list): wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}') - manufacturer_info = pn_info_string(HDR_MPN, + manufacturer_info = pn_info_string(HEADER_MPN, cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None, cable.mpn[i - 1] if isinstance(cable.mpn, list) else None) - supplier_info = pn_info_string(HDR_SPN, + supplier_info = pn_info_string(HEADER_SPN, cable.supplier[i - 1] if isinstance(cable.supplier, list) else None, cable.spn[i - 1] if isinstance(cable.spn, list) else None) if manufacturer_info: diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index aa77501..0d24a58 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -14,6 +14,10 @@ BOM_COLUMNS_ALWAYS = ('id', 'description', 'qty', 'unit', 'designators') BOM_COLUMNS_OPTIONAL = ('pn', 'manufacturer', 'mpn', 'supplier', 'spn') BOM_COLUMNS_IN_KEY = ('description', 'unit') + BOM_COLUMNS_OPTIONAL +HEADER_PN = 'P/N' +HEADER_MPN = 'MPN' +HEADER_SPN = 'SPN' + BOMKey = Tuple[str, ...] BOMColumn = str # = Literal[*BOM_COLUMNS_ALWAYS, *BOM_COLUMNS_OPTIONAL] BOMEntry = Dict[BOMColumn, Union[str, int, float, List[str], None]] @@ -143,9 +147,9 @@ def bom_list(bom: List[BOMEntry]) -> List[List[str]]: # Custom mapping from internal name to BOM column headers. # Headers not specified here are generated by capitilising the internal name. bom_headings = { - "pn": "P/N", - "mpn": HDR_MPN, - "spn": HDR_SPN, + "pn": HEADER_PN, + "mpn": HEADER_MPN, + "spn": HEADER_SPN, } return ([[bom_headings.get(k, k.capitalize()) for k in keys]] + # Create header row with key names [[make_str(entry.get(k)) for k in keys] for entry in bom]) # Create string list for each entry row @@ -162,9 +166,9 @@ def component_table_entry( ) -> str: """Return a diagram node table row string with an additional component.""" part_number_list = [ - pn, - pn_info_string(HDR_MPN, manufacturer, mpn), - pn_info_string(HDR_SPN, supplier, spn), + pn_info_string(HEADER_PN, None, pn), + pn_info_string(HEADER_MPN, manufacturer, mpn), + pn_info_string(HEADER_SPN, supplier, spn), ] output = (f'{qty}' + (f' {unit}' if unit else '')