generalize MPN/SPN string generation
rename `manufacturer_info_field()` to `pn_info_string()` and add parameter to specify MPN or SPN
This commit is contained in:
parent
0c1e7293dc
commit
6e59163cca
@ -14,7 +14,7 @@ from wireviz.DataClasses import Metadata, Options, Connector, Cable
|
||||
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 manufacturer_info_field, component_table_entry, \
|
||||
from wireviz.wv_bom import pn_info_string, component_table_entry, \
|
||||
get_additional_component_table, bom_list, generate_bom
|
||||
from wireviz.wv_html import generate_html_output
|
||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \
|
||||
@ -125,8 +125,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(manufacturer_info_field(connector.manufacturer, connector.mpn)),
|
||||
html_line_breaks(manufacturer_info_field(connector.supplier, connector.spn))],
|
||||
html_line_breaks(pn_info_string("mpn", connector.manufacturer, connector.mpn)),
|
||||
html_line_breaks(pn_info_string("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 +209,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(manufacturer_info_field(
|
||||
html_line_breaks(pn_info_string("mpn",
|
||||
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
|
||||
cable.mpn if not isinstance(cable.mpn, list) else None)),
|
||||
html_line_breaks(manufacturer_info_field(
|
||||
html_line_breaks(pn_info_string("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 +267,10 @@ class Harness:
|
||||
wireidentification = []
|
||||
if isinstance(cable.pn, list):
|
||||
wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}')
|
||||
manufacturer_info = manufacturer_info_field(
|
||||
manufacturer_info = pn_info_string("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 = manufacturer_info_field(
|
||||
supplier_info = pn_info_string("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:
|
||||
|
||||
@ -161,8 +161,8 @@ def component_table_entry(
|
||||
spn: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Return a diagram node table row string with an additional component."""
|
||||
manufacturer_str = manufacturer_info_field(manufacturer, mpn)
|
||||
supplier_str = manufacturer_info_field(supplier, spn)
|
||||
manufacturer_str = pn_info_string("mpn", manufacturer, mpn)
|
||||
supplier_str = pn_info_string("spn", supplier, spn)
|
||||
part_number_list = [pn, manufacturer_str, supplier_str]
|
||||
output = (f'{qty}'
|
||||
+ (f' {unit}' if unit else '')
|
||||
@ -175,10 +175,10 @@ def component_table_entry(
|
||||
<td align="left" balign="left">{html_line_breaks(output)}</td>
|
||||
</tr></table>'''
|
||||
|
||||
def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]:
|
||||
"""Return the manufacturer and/or the mpn in one single string or None otherwise."""
|
||||
if manufacturer or mpn:
|
||||
return f'{manufacturer if manufacturer else "MPN"}{": " + str(mpn) if mpn else ""}'
|
||||
def pn_info_string(nametype: str, name: Optional[str], number: Optional[str]) -> Optional[str]:
|
||||
"""Return the company name and/or the part number in one single string or None otherwise."""
|
||||
if name or number:
|
||||
return f'{name if name else nametype.upper()}{": " + str(number) if number else ""}'
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user