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

View File

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

View File

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

View File

@ -23,7 +23,8 @@ format_codes = {
"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()])

View File

@ -3,177 +3,38 @@
from typing import Dict, List
COLOR_CODES = {
# fmt: off
"DIN": [
"WH",
"BN",
"GN",
"YE",
"GY",
"PK",
"BU",
"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",
"WH", "BN", "GN", "YE", "GY", "PK", "BU", "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"],
"BW": ["BK", "WH"],
# 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).
# 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
"BUWH",
"WHBU",
"OGWH",
"WHOG",
"GNWH",
"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",
"BUWH", "WHBU", "OGWH", "WHOG", "GNWH", "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
"WHBU",
"BU",
"WHOG",
"OG",
"WHGN",
"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",
"WHBU", "BU", "WHOG", "OG", "WHGN", "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"],
"T568B": ["WHOG", "OG", "WHGN", "BU", "WHBU", "GN", "WHBN", "BN"],
}

View File

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

View File

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

View File

@ -104,14 +104,15 @@ def generate_html_output(
replacements['"sheetsize_default"'] = '"{}"'.format(
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
# regex replacement adapted from:
# 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)
pattern = re.compile("|".join(replacements_escaped))
html = pattern.sub(lambda match: replacements[match.group(0)], html)