Fix BOM output in TSV and HTML
This commit is contained in:
parent
af230a4a5c
commit
7d49f50984
@ -67,8 +67,11 @@ def pn_info_string(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def print_bom_debug(bom):
|
def bom_list(bom):
|
||||||
headers = "# qty unit description amount unit designators category pn manufacturer mpn supplier spn".split(" ")
|
headers = (
|
||||||
|
"# Qty Unit Description Amount Unit Designators "
|
||||||
|
"P/N Manufacturer MPN Supplier SPN Category".split(" ")
|
||||||
|
)
|
||||||
rows = []
|
rows = []
|
||||||
rows.append(headers)
|
rows.append(headers)
|
||||||
# fill rows
|
# fill rows
|
||||||
@ -81,18 +84,20 @@ def print_bom_debug(bom):
|
|||||||
hash.amount.number if hash.amount else None,
|
hash.amount.number if hash.amount else None,
|
||||||
hash.amount.unit if hash.amount else None,
|
hash.amount.unit if hash.amount else None,
|
||||||
", ".join(sorted(entry["designators"])),
|
", ".join(sorted(entry["designators"])),
|
||||||
f"{entry['category']} ({entry['category'].name})",
|
|
||||||
]
|
]
|
||||||
if hash.partnumbers:
|
if hash.partnumbers:
|
||||||
cells.extend([
|
cells.extend(
|
||||||
hash.partnumbers.pn,
|
[
|
||||||
hash.partnumbers.manufacturer,
|
hash.partnumbers.pn,
|
||||||
hash.partnumbers.mpn,
|
hash.partnumbers.manufacturer,
|
||||||
hash.partnumbers.supplier,
|
hash.partnumbers.mpn,
|
||||||
hash.partnumbers.spn,
|
hash.partnumbers.supplier,
|
||||||
])
|
hash.partnumbers.spn,
|
||||||
|
]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
cells.extend([None,None,None,None,None])
|
cells.extend([None, None, None, None, None])
|
||||||
|
# cells.extend([f"{entry['category']} ({entry['category'].name})"]) # for debugging
|
||||||
rows.append(cells)
|
rows.append(cells)
|
||||||
# remove empty columns
|
# remove empty columns
|
||||||
transposed = list(map(list, zip(*rows)))
|
transposed = list(map(list, zip(*rows)))
|
||||||
@ -103,7 +108,10 @@ def print_bom_debug(bom):
|
|||||||
# ^ ignore header cell in check
|
# ^ ignore header cell in check
|
||||||
]
|
]
|
||||||
rows = list(map(list, zip(*transposed)))
|
rows = list(map(list, zip(*transposed)))
|
||||||
# output
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
def print_bom_table(bom):
|
||||||
print()
|
print()
|
||||||
print(tabulate_module.tabulate(rows, headers="firstrow"))
|
print(tabulate_module.tabulate(bom_list(bom), headers="firstrow"))
|
||||||
print()
|
print()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from typing import List
|
|||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
|
|
||||||
import wireviz.wv_colors
|
import wireviz.wv_colors
|
||||||
from wireviz.wv_bom import BomCategory, BomEntry, print_bom_debug
|
from wireviz.wv_bom import BomCategory, BomEntry, bom_list, print_bom_table
|
||||||
from wireviz.wv_dataclasses import (
|
from wireviz.wv_dataclasses import (
|
||||||
AUTOGENERATED_PREFIX,
|
AUTOGENERATED_PREFIX,
|
||||||
AdditionalComponent,
|
AdditionalComponent,
|
||||||
@ -36,7 +36,7 @@ from wireviz.wv_graphviz import (
|
|||||||
set_dot_basics,
|
set_dot_basics,
|
||||||
)
|
)
|
||||||
from wireviz.wv_output import embed_svg_images_file, generate_html_output
|
from wireviz.wv_output import embed_svg_images_file, generate_html_output
|
||||||
from wireviz.wv_utils import open_file_write, tuplelist2tsv
|
from wireviz.wv_utils import bom2tsv, open_file_write
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -130,7 +130,7 @@ class Harness:
|
|||||||
continue
|
continue
|
||||||
item.bom_id = self.bom[item.bom_hash]["id"]
|
item.bom_id = self.bom[item.bom_hash]["id"]
|
||||||
|
|
||||||
print_bom_debug(self.bom)
|
print_bom_table(self.bom)
|
||||||
|
|
||||||
def _add_to_internal_bom(self, item: Component):
|
def _add_to_internal_bom(self, item: Component):
|
||||||
if item.ignore_in_bom:
|
if item.ignore_in_bom:
|
||||||
@ -293,7 +293,9 @@ class Harness:
|
|||||||
for connector in self.connectors.values():
|
for connector in self.connectors.values():
|
||||||
# generate connector node
|
# generate connector node
|
||||||
gv_html = gv_node_component(connector)
|
gv_html = gv_node_component(connector)
|
||||||
gv_html.update_attribs(bgcolor=calculate_node_bgcolor(connector, self.options))
|
gv_html.update_attribs(
|
||||||
|
bgcolor=calculate_node_bgcolor(connector, self.options)
|
||||||
|
)
|
||||||
dot.node(
|
dot.node(
|
||||||
connector.designator,
|
connector.designator,
|
||||||
label=f"<\n{gv_html}\n>",
|
label=f"<\n{gv_html}\n>",
|
||||||
@ -401,11 +403,11 @@ class Harness:
|
|||||||
if "gv" in fmt:
|
if "gv" in fmt:
|
||||||
graph.save(filename=f"{filename}.gv")
|
graph.save(filename=f"{filename}.gv")
|
||||||
# BOM output
|
# BOM output
|
||||||
# bommy = self.bom
|
bomlist = bom_list(self.bom)
|
||||||
# bomlist = bom_list(bommy)
|
# bomlist = [[]]
|
||||||
bomlist = [[]]
|
|
||||||
if "tsv" in fmt:
|
if "tsv" in fmt:
|
||||||
open_file_write(f"{filename}.tsv").write(tuplelist2tsv(bomlist))
|
tsv = bom2tsv(bomlist)
|
||||||
|
open_file_write(f"{filename}.tsv").write(tsv)
|
||||||
if "csv" in fmt:
|
if "csv" in fmt:
|
||||||
# TODO: implement CSV output (preferrably using CSV library)
|
# TODO: implement CSV output (preferrably using CSV library)
|
||||||
print("CSV output is not yet supported")
|
print("CSV output is not yet supported")
|
||||||
@ -422,8 +424,3 @@ class Harness:
|
|||||||
Path(f"{filename}.tmp.svg").unlink()
|
Path(f"{filename}.tmp.svg").unlink()
|
||||||
elif "svg" in fmt:
|
elif "svg" in fmt:
|
||||||
Path(f"{filename}.tmp.svg").replace(f"{filename}.svg")
|
Path(f"{filename}.tmp.svg").replace(f"{filename}.svg")
|
||||||
|
|
||||||
# def bom(self):
|
|
||||||
# if not self._bom:
|
|
||||||
# self._bom = generate_bom(self)
|
|
||||||
# return self._bom
|
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import wireviz # for doing wireviz.__file__
|
|||||||
from wireviz import APP_NAME, APP_URL, __version__
|
from wireviz import APP_NAME, APP_URL, __version__
|
||||||
from wireviz.wv_dataclasses import Metadata, Options
|
from wireviz.wv_dataclasses import Metadata, Options
|
||||||
from wireviz.wv_utils import (
|
from wireviz.wv_utils import (
|
||||||
flatten2d,
|
|
||||||
html_line_breaks,
|
html_line_breaks,
|
||||||
open_file_read,
|
open_file_read,
|
||||||
open_file_write,
|
open_file_write,
|
||||||
@ -65,7 +64,7 @@ def embed_svg_images_file(
|
|||||||
|
|
||||||
def generate_html_output(
|
def generate_html_output(
|
||||||
filename: Union[str, Path],
|
filename: Union[str, Path],
|
||||||
bom_list: List[List[str]],
|
bom: List[List[str]],
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
options: Options,
|
options: Options,
|
||||||
):
|
):
|
||||||
@ -95,8 +94,6 @@ def generate_html_output(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# generate BOM table
|
# generate BOM table
|
||||||
bom = flatten2d(bom_list)
|
|
||||||
|
|
||||||
# generate BOM header (may be at the top or bottom of the table)
|
# generate BOM header (may be at the top or bottom of the table)
|
||||||
bom_header_html = " <tr>\n"
|
bom_header_html = " <tr>\n"
|
||||||
for item in bom[0]:
|
for item in bom[0]:
|
||||||
@ -110,7 +107,7 @@ def generate_html_output(
|
|||||||
row_html = " <tr>\n"
|
row_html = " <tr>\n"
|
||||||
for i, item in enumerate(row):
|
for i, item in enumerate(row):
|
||||||
td_class = f"bom_col_{bom[0][i].lower()}"
|
td_class = f"bom_col_{bom[0][i].lower()}"
|
||||||
row_html = f'{row_html} <td class="{td_class}">{item}</td>\n'
|
row_html = f'{row_html} <td class="{td_class}">{item if item is not None else ""}</td>\n'
|
||||||
row_html = f"{row_html} </tr>\n"
|
row_html = f"{row_html} </tr>\n"
|
||||||
bom_contents.append(row_html)
|
bom_contents.append(row_html)
|
||||||
|
|
||||||
|
|||||||
@ -90,12 +90,12 @@ def flatten2d(inp):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def tuplelist2tsv(inp, header=None):
|
def bom2tsv(inp, header=None):
|
||||||
output = ""
|
output = ""
|
||||||
if header is not None:
|
if header is not None:
|
||||||
inp.insert(0, header)
|
inp.insert(0, header)
|
||||||
inp = flatten2d(inp)
|
|
||||||
for row in inp:
|
for row in inp:
|
||||||
|
row = [item if item is not None else "" for item in row]
|
||||||
output = output + "\t".join(str(remove_links(item)) for item in row) + "\n"
|
output = output + "\t".join(str(remove_links(item)) for item in row) + "\n"
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user