Apply some manual fixes, reapply black

This commit is contained in:
Daniel Rojas 2021-10-15 17:39:33 +02:00
parent f92985a61c
commit c89cf735ae
9 changed files with 147 additions and 354 deletions

View File

@ -98,13 +98,12 @@ class Image:
self.fixedsize = (self.width or self.height) and self.scale is None self.fixedsize = (self.width or self.height) and self.scale is None
if self.scale is None: if self.scale is None:
self.scale = ( if not self.width and not self.height:
"false" self.scale = "false"
if not self.width and not self.height elif self.width and self.height:
else "both" self.scale = "both"
if self.width and self.height else:
else "true" self.scale = "true" # When only one dimension is specified.
) # When only one dimension is specified.
if self.fixedsize: if self.fixedsize:
# If only one dimension is specified, compute the other # If only one dimension is specified, compute the other
@ -133,9 +132,8 @@ class AdditionalComponent:
@property @property
def description(self) -> str: def description(self) -> str:
return self.type.rstrip() + ( s = self.type.rstrip() + f", {self.subtype.rstrip()}" if self.subtype else ""
f", {self.subtype.rstrip()}" if self.subtype else "" return s
)
@dataclass @dataclass
@ -203,9 +201,8 @@ class Connector:
self.show_name = self.style != "simple" and self.name[0:2] != "__" self.show_name = self.style != "simple" and self.name[0:2] != "__"
if self.show_pincount is None: if self.show_pincount is None:
self.show_pincount = ( # hide pincount for simple (1 pin) connectors by default
self.style != "simple" self.show_pincount = self.style != "simple"
) # hide pincount for simple (1 pin) connectors by default
for loop in self.loops: for loop in self.loops:
# TODO: check that pins to connect actually exist # TODO: check that pins to connect actually exist
@ -322,9 +319,8 @@ class Cable:
if self.wirecount: # number of wires explicitly defined if self.wirecount: # number of wires explicitly defined
if self.colors: # use custom color palette (partly or looped if needed) if self.colors: # use custom color palette (partly or looped if needed)
pass pass
elif ( elif self.color_code:
self.color_code # use standard color palette (partly or looped if needed)
): # use standard color palette (partly or looped if needed)
if self.color_code not in COLOR_CODES: if self.color_code not in COLOR_CODES:
raise Exception("Unknown color code") raise Exception("Unknown color code")
self.colors = COLOR_CODES[self.color_code] self.colors = COLOR_CODES[self.color_code]
@ -361,14 +357,12 @@ class Cable:
raise Exception("lists of part data are only supported for bundles") raise Exception("lists of part data are only supported for bundles")
if self.show_name is None: if self.show_name is None:
self.show_name = ( # hide designators for auto-generated cables by default
self.name[0:2] != "__" self.show_name = self.name[0:2] != "__"
) # hide designators for auto-generated cables by default
if not self.show_wirenumbers: if not self.show_wirenumbers:
self.show_wirenumbers = ( # by default, show wire numbers for cables, hide for bundles
self.category != "bundle" self.show_wirenumbers = self.category != "bundle"
) # by default, show wire numbers for cables, hide for bundles
for i, item in enumerate(self.additional_components): for i, item in enumerate(self.additional_components):
if isinstance(item, dict): if isinstance(item, dict):
@ -383,6 +377,7 @@ class Cable:
to_name: Optional[Designator], to_name: Optional[Designator],
to_pin: NoneOrMorePinIndices, to_pin: NoneOrMorePinIndices,
) -> None: ) -> None:
from_pin = int2tuple(from_pin) from_pin = int2tuple(from_pin)
via_wire = int2tuple(via_wire) via_wire = int2tuple(via_wire)
to_pin = int2tuple(to_pin) to_pin = int2tuple(to_pin)

View File

@ -130,9 +130,8 @@ class Harness:
raise Exception( raise Exception(
f"{via_name}:{via_wire} is used for more than one wire." f"{via_name}:{via_wire} is used for more than one wire."
) )
via_wire = ( # list index starts at 0, wire IDs start at 1
cable.colors.index(via_wire) + 1 via_wire = cable.colors.index(via_wire) + 1
) # list index starts at 0, wire IDs start at 1
elif via_wire in cable.wirelabels: elif via_wire in cable.wirelabels:
if cable.wirelabels.count(via_wire) > 1: if cable.wirelabels.count(via_wire) > 1:
raise Exception( raise Exception(
@ -180,37 +179,22 @@ class Harness:
connector.ports_left = True # Use left side pins. connector.ports_left = True # Use left side pins.
html = [] html = []
# fmt: off
rows = [[f'{html_bgcolor(connector.bgcolor_title)}{remove_links(connector.name)}'
if connector.show_name else None],
[pn_info_string(HEADER_PN, None, remove_links(connector.pn)),
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,
translate_color(connector.color, self.options.color_mode) if connector.color else None,
html_colorbar(connector.color)],
'<!-- connector table -->' if connector.style != 'simple' else None,
[html_image(connector.image)],
[html_caption(connector.image)]]
# fmt: on
rows = [
[
f"{html_bgcolor(connector.bgcolor_title)}{remove_links(connector.name)}"
if connector.show_name
else None
],
[
pn_info_string(HEADER_PN, None, remove_links(connector.pn)),
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,
translate_color(connector.color, self.options.color_mode)
if connector.color
else None,
html_colorbar(connector.color),
],
"<!-- connector table -->" if connector.style != "simple" else None,
[html_image(connector.image)],
[html_caption(connector.image)],
]
rows.extend(get_additional_component_table(self, connector)) rows.extend(get_additional_component_table(self, connector))
rows.append([html_line_breaks(connector.notes)]) rows.append([html_line_breaks(connector.notes)])
html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor))) html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor)))
@ -231,6 +215,7 @@ class Harness:
and not connector.visible_pins.get(pinname, False) and not connector.visible_pins.get(pinname, False)
): ):
continue continue
pinhtml.append(" <tr>") pinhtml.append(" <tr>")
if connector.ports_left: if connector.ports_left:
pinhtml.append(f' <td port="p{pinindex+1}l">{pinname}</td>') pinhtml.append(f' <td port="p{pinindex+1}l">{pinname}</td>')
@ -238,16 +223,14 @@ class Harness:
pinhtml.append(f" <td>{pinlabel}</td>") pinhtml.append(f" <td>{pinlabel}</td>")
if connector.pincolors: if connector.pincolors:
if pincolor in wv_colors._color_hex.keys(): if pincolor in wv_colors._color_hex.keys():
pinhtml.append( # fmt: off
f' <td sides="tbl">{translate_color(pincolor, self.options.color_mode)}</td>' pinhtml.append(f' <td sides="tbl">{translate_color(pincolor, self.options.color_mode)}</td>')
) pinhtml.append( ' <td sides="tbr">')
pinhtml.append(' <td sides="tbr">') pinhtml.append( ' <table border="0" cellborder="1"><tr>')
pinhtml.append(' <table border="0" cellborder="1"><tr>') pinhtml.append(f' <td bgcolor="{wv_colors.translate_color(pincolor, "HEX")}" width="8" height="8" fixedsize="true"></td>')
pinhtml.append( pinhtml.append( ' </tr></table>')
f' <td bgcolor="{wv_colors.translate_color(pincolor, "HEX")}" width="8" height="8" fixedsize="true"></td>' pinhtml.append( ' </td>')
) # fmt: on
pinhtml.append(" </tr></table>")
pinhtml.append(" </td>")
else: else:
pinhtml.append(' <td colspan="2"></td>') pinhtml.append(' <td colspan="2"></td>')
@ -309,61 +292,36 @@ class Harness:
elif cable.gauge_unit.upper() == "AWG": elif cable.gauge_unit.upper() == "AWG":
awg_fmt = f" ({mm2_equiv(cable.gauge)} mm\u00B2)" awg_fmt = f" ({mm2_equiv(cable.gauge)} mm\u00B2)"
rows = [ # fmt: off
[ rows = [[f'{html_bgcolor(cable.bgcolor_title)}{remove_links(cable.name)}'
f"{html_bgcolor(cable.bgcolor_title)}{remove_links(cable.name)}" if cable.show_name else None],
if cable.show_name [pn_info_string(HEADER_PN, None,
else None remove_links(cable.pn)) if not isinstance(cable.pn, list) else None,
], html_line_breaks(pn_info_string(HEADER_MPN,
[ cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
pn_info_string(HEADER_PN, None, remove_links(cable.pn)) cable.mpn if not isinstance(cable.mpn, list) else None)),
if not isinstance(cable.pn, list) html_line_breaks(pn_info_string(HEADER_SPN,
else None, cable.supplier if not isinstance(cable.supplier, list) else None,
html_line_breaks( cable.spn if not isinstance(cable.spn, list) else None))],
pn_info_string( [html_line_breaks(cable.type),
HEADER_MPN, f'{cable.wirecount}x' if cable.show_wirecount else None,
cable.manufacturer f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None,
if not isinstance(cable.manufacturer, list) '+ S' if cable.shield else None,
else None, f'{cable.length} {cable.length_unit}' if cable.length > 0 else None,
cable.mpn if not isinstance(cable.mpn, list) else None, translate_color(cable.color, self.options.color_mode) if cable.color else None,
) html_colorbar(cable.color)],
), '<!-- wire table -->',
html_line_breaks( [html_image(cable.image)],
pn_info_string( [html_caption(cable.image)]]
HEADER_SPN, # fmt: on
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),
f"{cable.wirecount}x" if cable.show_wirecount else None,
f"{cable.gauge} {cable.gauge_unit}{awg_fmt}"
if cable.gauge
else None,
"+ S" if cable.shield else None,
f"{cable.length} {cable.length_unit}" if cable.length > 0 else None,
translate_color(cable.color, self.options.color_mode)
if cable.color
else None,
html_colorbar(cable.color),
],
"<!-- wire table -->",
[html_image(cable.image)],
[html_caption(cable.image)],
]
rows.extend(get_additional_component_table(self, cable)) rows.extend(get_additional_component_table(self, cable))
rows.append([html_line_breaks(cable.notes)]) rows.append([html_line_breaks(cable.notes)])
html.extend(nested_html_table(rows, html_bgcolor_attr(cable.bgcolor))) html.extend(nested_html_table(rows, html_bgcolor_attr(cable.bgcolor)))
wirehtml = [] wirehtml = []
wirehtml.append( # conductor table
'<table border="0" cellspacing="0" cellborder="0">' wirehtml.append('<table border="0" cellspacing="0" cellborder="0">')
) # conductor table
wirehtml.append(" <tr><td>&nbsp;</td></tr>") wirehtml.append(" <tr><td>&nbsp;</td></tr>")
for i, (connection_color, wirelabel) in enumerate( for i, (connection_color, wirelabel) in enumerate(
@ -389,28 +347,20 @@ class Harness:
wirehtml.append(f" <td><!-- {i}_out --></td>") wirehtml.append(f" <td><!-- {i}_out --></td>")
wirehtml.append(" </tr>") wirehtml.append(" </tr>")
bgcolors = ( # fmt: off
["#000000"] + get_color_hex(connection_color, pad=pad) + ["#000000"] bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000']
)
wirehtml.append(f" <tr>") wirehtml.append(f" <tr>")
wirehtml.append( wirehtml.append(f' <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">')
f' <td colspan="3" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}">' wirehtml.append(' <table cellspacing="0" cellborder="0" border="0">')
) for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
wirehtml.append( wirehtml.append(f' <tr><td colspan="3" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>')
' <table cellspacing="0" cellborder="0" border="0">'
)
for j, bgcolor in enumerate(
bgcolors[::-1]
): # Reverse to match the curved wires when more than 2 colors
wirehtml.append(
f' <tr><td colspan="3" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>'
)
wirehtml.append(" </table>") wirehtml.append(" </table>")
wirehtml.append(" </td>") wirehtml.append(" </td>")
wirehtml.append(" </tr>") wirehtml.append(" </tr>")
if ( # fmt: on
cable.category == "bundle"
): # for bundles individual wires can have part information # for bundles, individual wires can have part information
if cable.category == "bundle":
# create a list of wire parameters # create a list of wire parameters
wireidentification = [] wireidentification = []
if isinstance(cable.pn, list): if isinstance(cable.pn, list):
@ -439,14 +389,14 @@ class Harness:
wireidentification.append(html_line_breaks(supplier_info)) wireidentification.append(html_line_breaks(supplier_info))
# print parameters into a table row under the wire # print parameters into a table row under the wire
if len(wireidentification) > 0: if len(wireidentification) > 0:
# fmt: off
wirehtml.append(' <tr><td colspan="3">') wirehtml.append(' <tr><td colspan="3">')
wirehtml.append( wirehtml.append(' <table border="0" cellspacing="0" cellborder="0"><tr>')
' <table border="0" cellspacing="0" cellborder="0"><tr>'
)
for attrib in wireidentification: for attrib in wireidentification:
wirehtml.append(f" <td>{attrib}</td>") wirehtml.append(f" <td>{attrib}</td>")
wirehtml.append(" </tr></table>") wirehtml.append(" </tr></table>")
wirehtml.append(" </td></tr>") wirehtml.append(" </td></tr>")
# fmt: on
if cable.shield: if cable.shield:
wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer wirehtml.append(" <tr><td>&nbsp;</td></tr>") # spacer
@ -464,9 +414,9 @@ class Harness:
else: else:
# shield is shown as a thin black wire # shield is shown as a thin black wire
attributes = f'height="2" bgcolor="#000000" border="0"' attributes = f'height="2" bgcolor="#000000" border="0"'
wirehtml.append( # fmt: off
f' <tr><td colspan="3" cellpadding="0" {attributes} port="ws"></td></tr>' wirehtml.append(f' <tr><td colspan="3" cellpadding="0" {attributes} port="ws"></td></tr>')
) # fmt: on
wirehtml.append(" <tr><td>&nbsp;</td></tr>") wirehtml.append(" <tr><td>&nbsp;</td></tr>")
wirehtml.append(" </table>") wirehtml.append(" </table>")
@ -477,9 +427,8 @@ class Harness:
# connections # connections
for connection in cable.connections: for connection in cable.connections:
if isinstance( if isinstance(connection.via_port, int):
connection.via_port, int # check if it's an actual wire and not a shield
): # check if it's an actual wire and not a shield
dot.attr( dot.attr(
"edge", "edge",
color=":".join( color=":".join(
@ -734,15 +683,15 @@ class Harness:
with open_file_write(f"{filename}.bom.tsv") as file: with open_file_write(f"{filename}.bom.tsv") as file:
file.write(tuplelist2tsv(bomlist)) file.write(tuplelist2tsv(bomlist))
if "csv" in fmt: if "csv" in fmt:
print( # TODO: implement CSV output (preferrably using CSV library)
"CSV output is not yet supported" print("CSV output is not yet supported")
) # TODO: implement CSV output (preferrably using CSV library)
# HTML output # HTML output
if "html" in fmt: if "html" in fmt:
generate_html_output(filename, bomlist, self.metadata, self.options) generate_html_output(filename, bomlist, self.metadata, self.options)
# PDF output # PDF output
if "pdf" in fmt: if "pdf" in fmt:
print("PDF output is not yet supported") # TODO: implement PDF output # TODO: implement PDF output
print("PDF output is not yet supported")
# delete SVG if not needed # delete SVG if not needed
if "html" in fmt and not "svg" in fmt and not svg_already_exists: if "html" in fmt and not "svg" in fmt and not svg_already_exists:
Path(f"{filename}.svg").unlink() Path(f"{filename}.svg").unlink()

View File

@ -86,12 +86,10 @@ def parse(
tweak=Tweak(**yaml_data.get("tweak", {})), tweak=Tweak(**yaml_data.get("tweak", {})),
) )
# others # others
designators_and_templates = ( # store mapping of components to their respective template
{} designators_and_templates = {}
) # store mapping of components to their respective template # keep track of auto-generated designators to avoid duplicates
autogenerated_designators = ( autogenerated_designators = {}
{}
) # keep track of auto-generated designators to avoid duplicates
if "title" not in harness.metadata: if "title" not in harness.metadata:
harness.metadata["title"] = Path(file_out).stem harness.metadata["title"] = Path(file_out).stem
@ -110,9 +108,8 @@ def parse(
image = attribs.get("image") image = attribs.get("image")
if isinstance(image, dict): if isinstance(image, dict):
image_path = image["src"] image_path = image["src"]
if ( if image_path and not Path(image_path).is_absolute():
image_path and not Path(image_path).is_absolute() # resolve relative image path
): # resolve relative image path
image["src"] = smart_file_resolve( image["src"] = smart_file_resolve(
image_path, image_paths image_path, image_paths
) )
@ -187,9 +184,8 @@ def parse(
if isinstance(entry, list): if isinstance(entry, list):
connectioncount.append(len(entry)) connectioncount.append(len(entry))
elif isinstance(entry, dict): elif isinstance(entry, dict):
connectioncount.append( connectioncount.append(len(expand(list(entry.values())[0])))
len(expand(list(entry.values())[0])) # e.g.: - X1: [1-4,6] yields 5
) # - X1: [1-4,6] yields 5
else: else:
pass # strings do not reveal connectioncount pass # strings do not reveal connectioncount
if not any(connectioncount): if not any(connectioncount):
@ -258,9 +254,8 @@ def parse(
if designator in harness.connectors: # existing connector instance if designator in harness.connectors: # existing connector instance
check_type(designator, template, "connector") check_type(designator, template, "connector")
elif ( elif template in template_connectors.keys():
template in template_connectors.keys() # generate new connector instance from template
): # generate new connector instance from template
check_type(designator, template, "connector") check_type(designator, template, "connector")
harness.add_connector( harness.add_connector(
name=designator, **template_connectors[template] name=designator, **template_connectors[template]
@ -268,9 +263,8 @@ def parse(
elif designator in harness.cables: # existing cable instance elif designator in harness.cables: # existing cable instance
check_type(designator, template, "cable/arrow") check_type(designator, template, "cable/arrow")
elif ( elif template in template_cables.keys():
template in template_cables.keys() # generate new cable instance from template
): # generate new cable instance from template
check_type(designator, template, "cable/arrow") check_type(designator, template, "cable/arrow")
harness.add_cable(name=designator, **template_cables[template]) harness.add_cable(name=designator, **template_cables[template])
@ -295,18 +289,16 @@ def parse(
designator = list(item.keys())[0] designator = list(item.keys())[0]
if designator in harness.cables: if designator in harness.cables:
if ( if index_item == 0:
index_item == 0 # list started with a cable, no connector to join on left side
): # list started with a cable, no connector to join on left side
from_name, from_pin = (None, None) from_name, from_pin = (None, None)
else: else:
from_name, from_pin = get_single_key_and_value( from_name, from_pin = get_single_key_and_value(
entry[index_item - 1] entry[index_item - 1]
) )
via_name, via_pin = (designator, item[designator]) via_name, via_pin = (designator, item[designator])
if ( if index_item == len(entry) - 1:
index_item == len(entry) - 1 # list ends with a cable, no connector to join on right side
): # list ends with a cable, no connector to join on right side
to_name, to_pin = (None, None) to_name, to_pin = (None, None)
else: else:
to_name, to_pin = get_single_key_and_value( to_name, to_pin = get_single_key_and_value(
@ -335,9 +327,8 @@ def parse(
harness.add_mate_pin( harness.add_mate_pin(
from_name, from_pin, to_name, to_pin, designator from_name, from_pin, to_name, to_pin, designator
) )
elif ( elif "=" in designator and index_entry == 0:
"=" in designator and index_entry == 0 # mate two connectors as a whole
): # mate two connectors as a whole
harness.add_mate_component(from_name, to_name, designator) harness.add_mate_component(from_name, to_name, designator)
# harness population completed ============================================= # harness population completed =============================================

View File

@ -214,11 +214,8 @@ def get_bom_index(bom: List[BOMEntry], target: BOMKey) -> int:
def bom_list(bom: List[BOMEntry]) -> List[List[str]]: def bom_list(bom: List[BOMEntry]) -> List[List[str]]:
"""Return list of BOM rows as lists of column strings with headings in top row.""" """Return list of BOM rows as lists of column strings with headings in top row."""
keys = list(BOM_COLUMNS_ALWAYS) # Always include this fixed set of BOM columns. keys = list(BOM_COLUMNS_ALWAYS) # Always include this fixed set of BOM columns.
for ( for fieldname in BOM_COLUMNS_OPTIONAL:
fieldname # Include only those optional BOM columns that are in use.
) in (
BOM_COLUMNS_OPTIONAL
): # Include only those optional BOM columns that are in use.
if any(entry.get(fieldname) for entry in bom): if any(entry.get(fieldname) for entry in bom):
keys.append(fieldname) keys.append(fieldname)
# Custom mapping from internal name to BOM column headers. # Custom mapping from internal name to BOM column headers.

View File

@ -23,7 +23,8 @@ format_codes = {
"t": "tsv", "t": "tsv",
} }
epilog = "The -f or --format option accepts a string containing one or more of the following characters to specify which file types to output:\n" epilog = "The -f or --format option accepts a string containing one or more of the "
epilog += "following characters to specify which file types to output:\n"
epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.items()]) epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.items()])

View File

@ -3,177 +3,38 @@
from typing import Dict, List from typing import Dict, List
COLOR_CODES = { COLOR_CODES = {
# fmt: off
"DIN": [ "DIN": [
"WH", "WH", "BN", "GN", "YE", "GY", "PK", "BU", "RD", "BK", "VT", "GYPK", "RDBU",
"BN", "WHGN", "BNGN", "WHYE", "YEBN", "WHGY", "GYBN", "WHPK", "PKBN", "WHBU", "BNBU",
"GN", "WHRD", "BNRD", "WHBK", "BNBK", "GYGN", "YEGY", "PKGN", "YEPK", "GNBU", "YEBU",
"YE", "GNRD", "YERD", "GNBK", "YEBK", "GYBU", "PKBU", "GYRD", "PKRD", "GYBK", "PKBK",
"GY", "BUBK", "RDBK", "WHBNBK", "YEGNBK", "GYPKBK", "RDBUBK", "WHGNBK", "BNGNBK",
"PK", "WHYEBK", "YEBNBK", "WHGYBK", "GYBNBK", "WHPKBK", "PKBNBK", "WHBUBK",
"BU", "BNBUBK", "WHRDBK", "BNRDBK",
"RD",
"BK",
"VT",
"GYPK",
"RDBU",
"WHGN",
"BNGN",
"WHYE",
"YEBN",
"WHGY",
"GYBN",
"WHPK",
"PKBN",
"WHBU",
"BNBU",
"WHRD",
"BNRD",
"WHBK",
"BNBK",
"GYGN",
"YEGY",
"PKGN",
"YEPK",
"GNBU",
"YEBU",
"GNRD",
"YERD",
"GNBK",
"YEBK",
"GYBU",
"PKBU",
"GYRD",
"PKRD",
"GYBK",
"PKBK",
"BUBK",
"RDBK",
"WHBNBK",
"YEGNBK",
"GYPKBK",
"RDBUBK",
"WHGNBK",
"BNGNBK",
"WHYEBK",
"YEBNBK",
"WHGYBK",
"GYBNBK",
"WHPKBK",
"PKBNBK",
"WHBUBK",
"BNBUBK",
"WHRDBK",
"BNRDBK",
], ],
# fmt: on
"IEC": ["BN", "RD", "OG", "YE", "GN", "BU", "VT", "GY", "WH", "BK"], "IEC": ["BN", "RD", "OG", "YE", "GN", "BU", "VT", "GY", "WH", "BK"],
"BW": ["BK", "WH"], "BW": ["BK", "WH"],
# 25-pair color code - see also https://en.wikipedia.org/wiki/25-pair_color_code # 25-pair color code - see also https://en.wikipedia.org/wiki/25-pair_color_code
# 5 major colors (WH,RD,BK,YE,VT) combined with 5 minor colors (BU,OG,GN,BN,SL). # 5 major colors (WH,RD,BK,YE,VT) combined with 5 minor colors (BU,OG,GN,BN,SL).
# Each POTS pair tip (+) had major/minor color, and ring (-) had minor/major color. # Each POTS pair tip (+) had major/minor color, and ring (-) had minor/major color.
# fmt: off
"TEL": [ # 25x2: Ring and then tip of each pair "TEL": [ # 25x2: Ring and then tip of each pair
"BUWH", "BUWH", "WHBU", "OGWH", "WHOG", "GNWH", "WHGN", "BNWH", "WHBN", "SLWH", "WHSL",
"WHBU", "BURD", "RDBU", "OGRD", "RDOG", "GNRD", "RDGN", "BNRD", "RDBN", "SLRD", "RDSL",
"OGWH", "BUBK", "BKBU", "OGBK", "BKOG", "GNBK", "BKGN", "BNBK", "BKBN", "SLBK", "BKSL",
"WHOG", "BUYE", "YEBU", "OGYE", "YEOG", "GNYE", "YEGN", "BNYE", "YEBN", "SLYE", "YESL",
"GNWH", "BUVT", "VTBU", "OGVT", "VTOG", "GNVT", "VTGN", "BNVT", "VTBN", "SLVT", "VTSL",
"WHGN",
"BNWH",
"WHBN",
"SLWH",
"WHSL",
"BURD",
"RDBU",
"OGRD",
"RDOG",
"GNRD",
"RDGN",
"BNRD",
"RDBN",
"SLRD",
"RDSL",
"BUBK",
"BKBU",
"OGBK",
"BKOG",
"GNBK",
"BKGN",
"BNBK",
"BKBN",
"SLBK",
"BKSL",
"BUYE",
"YEBU",
"OGYE",
"YEOG",
"GNYE",
"YEGN",
"BNYE",
"YEBN",
"SLYE",
"YESL",
"BUVT",
"VTBU",
"OGVT",
"VTOG",
"GNVT",
"VTGN",
"BNVT",
"VTBN",
"SLVT",
"VTSL",
], ],
"TELALT": [ # 25x2: Tip and then ring of each pair "TELALT": [ # 25x2: Tip and then ring of each pair
"WHBU", "WHBU", "BU", "WHOG", "OG", "WHGN", "GN", "WHBN", "BN", "WHSL", "SL",
"BU", "RDBU", "BURD", "RDOG", "OGRD", "RDGN", "GNRD", "RDBN", "BNRD", "RDSL", "SLRD",
"WHOG", "BKBU", "BUBK", "BKOG", "OGBK", "BKGN", "GNBK", "BKBN", "BNBK", "BKSL", "SLBK",
"OG", "YEBU", "BUYE", "YEOG", "OGYE", "YEGN", "GNYE", "YEBN", "BNYE", "YESL", "SLYE",
"WHGN", "VTBU", "BUVT", "VTOG", "OGVT", "VTGN", "GNVT", "VTBN", "BNVT", "VTSL", "SLVT",
"GN",
"WHBN",
"BN",
"WHSL",
"SL",
"RDBU",
"BURD",
"RDOG",
"OGRD",
"RDGN",
"GNRD",
"RDBN",
"BNRD",
"RDSL",
"SLRD",
"BKBU",
"BUBK",
"BKOG",
"OGBK",
"BKGN",
"GNBK",
"BKBN",
"BNBK",
"BKSL",
"SLBK",
"YEBU",
"BUYE",
"YEOG",
"OGYE",
"YEGN",
"GNYE",
"YEBN",
"BNYE",
"YESL",
"SLYE",
"VTBU",
"BUVT",
"VTOG",
"OGVT",
"VTGN",
"GNVT",
"VTBN",
"BNVT",
"VTSL",
"SLVT",
], ],
# fmt: on
"T568A": ["WHGN", "GN", "WHOG", "BU", "WHBU", "OG", "WHBN", "BN"], "T568A": ["WHGN", "GN", "WHOG", "BU", "WHBU", "OG", "WHBN", "BN"],
"T568B": ["WHOG", "OG", "WHGN", "BU", "WHBU", "GN", "WHBN", "BN"], "T568B": ["WHOG", "OG", "WHGN", "BU", "WHBU", "GN", "WHBN", "BN"],
} }

View File

@ -25,15 +25,15 @@ def nested_html_table(
if isinstance(row, List): if isinstance(row, List):
if len(row) > 0 and any(row): if len(row) > 0 and any(row):
html.append(" <tr><td>") html.append(" <tr><td>")
html.append( # fmt: off
' <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>' html.append(' <table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>')
) # fmt: on
for cell in row: for cell in row:
if cell is not None: if cell is not None:
# Inject attributes to the preceeding <td> tag where needed # Inject attributes to the preceeding <td> tag where needed
html.append( # fmt: off
f' <td balign="left">{cell}</td>'.replace("><tdX", "") html.append(f' <td balign="left">{cell}</td>'.replace("><tdX", ""))
) # fmt: on
html.append(" </tr></table>") html.append(" </tr></table>")
html.append(" </td></tr>") html.append(" </td></tr>")
num_rows = num_rows + 1 num_rows = num_rows + 1
@ -43,9 +43,8 @@ def nested_html_table(
html.append(" </td></tr>") html.append(" </td></tr>")
num_rows = num_rows + 1 num_rows = num_rows + 1
if num_rows == 0: # empty table if num_rows == 0: # empty table
html.append( # generate empty cell to avoid GraphViz errors
"<tr><td></td></tr>" html.append("<tr><td></td></tr>")
) # generate empty cell to avoid GraphViz errors
html.append("</table>") html.append("</table>")
return html return html

View File

@ -58,9 +58,8 @@ def expand(yaml_data):
else: # a == b else: # a == b
output.append(a) # range of length 1 output.append(a) # range of length 1
except: except:
output.append( # '-' was not a delimiter between two ints, pass e through unchanged
e output.append(e)
) # '-' was not a delimiter between two ints, pass e through unchanged
else: else:
try: try:
x = int(e) # single int x = int(e) # single int

View File

@ -104,14 +104,15 @@ def generate_html_output(
replacements['"sheetsize_default"'] = '"{}"'.format( replacements['"sheetsize_default"'] = '"{}"'.format(
metadata.get("template", {}).get("sheetsize", "") metadata.get("template", {}).get("sheetsize", "")
) # include quotes so no replacement happens within <style> definition )
# include quotes so no replacement happens within <style> definition
# perform replacements # perform replacements
# regex replacement adapted from: # regex replacement adapted from:
# https://gist.github.com/bgusach/a967e0587d6e01e889fd1d776c5f3729 # https://gist.github.com/bgusach/a967e0587d6e01e889fd1d776c5f3729
replacements_sorted = sorted(
replacements, key=len, reverse=True # longer replacements first, just in case
) # longer replacements first, just in case replacements_sorted = sorted(replacements, key=len, reverse=True)
replacements_escaped = map(re.escape, replacements_sorted) replacements_escaped = map(re.escape, replacements_sorted)
pattern = re.compile("|".join(replacements_escaped)) pattern = re.compile("|".join(replacements_escaped))
html = pattern.sub(lambda match: replacements[match.group(0)], html) html = pattern.sub(lambda match: replacements[match.group(0)], html)