bom: flag to restrict_printed_lengths
This commit is contained in:
parent
0f06b45c06
commit
1ea0b9febd
@ -35,11 +35,12 @@ def partnumbers2list(
|
|||||||
return [p.str_list for p in partnumbers if p]
|
return [p.str_list for p in partnumbers if p]
|
||||||
|
|
||||||
|
|
||||||
def bom_list(bom):
|
def bom_list(bom, restrict_printed_lengths=True):
|
||||||
entries_as_dict = []
|
entries_as_dict = []
|
||||||
has_content = set()
|
has_content = set()
|
||||||
# First pass, get all bom dict and identify filled columns
|
# First pass, get all bom dict and identify filled columns
|
||||||
for entry in bom.values():
|
for entry in bom.values():
|
||||||
|
entry.restrict_printed_lengths = restrict_printed_lengths
|
||||||
has_content = has_content.union(entry.bom_defined)
|
has_content = has_content.union(entry.bom_defined)
|
||||||
entries_as_dict.append(entry.bom_dict)
|
entries_as_dict.append(entry.bom_dict)
|
||||||
|
|
||||||
|
|||||||
@ -155,6 +155,7 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi
|
|||||||
)
|
)
|
||||||
shared_bom = ret["shared_bom"]
|
shared_bom = ret["shared_bom"]
|
||||||
|
|
||||||
|
# TODO: move shared bom generation to a method?
|
||||||
if "shared_bom" in output_formats:
|
if "shared_bom" in output_formats:
|
||||||
shared_bom_file = (_output_dir / "shared_bom").with_suffix(".tsv")
|
shared_bom_file = (_output_dir / "shared_bom").with_suffix(".tsv")
|
||||||
print(f'Generating shared bom at {shared_bom_file}')
|
print(f'Generating shared bom at {shared_bom_file}')
|
||||||
@ -166,7 +167,7 @@ def cli(files, formats, prepend, output_dir, output_name, version, use_qty_multi
|
|||||||
for bom_item in shared_bom.values():
|
for bom_item in shared_bom.values():
|
||||||
bom_item.scale_per_harness(qty_multipliers)
|
bom_item.scale_per_harness(qty_multipliers)
|
||||||
|
|
||||||
shared_bomlist = bom_list(shared_bom)
|
shared_bomlist = bom_list(shared_bom, False)
|
||||||
|
|
||||||
shared_bom_tsv = bom2tsv(shared_bomlist)
|
shared_bom_tsv = bom2tsv(shared_bomlist)
|
||||||
shared_bom_file.open("w").write(shared_bom_tsv)
|
shared_bom_file.open("w").write(shared_bom_tsv)
|
||||||
|
|||||||
@ -268,8 +268,6 @@ class BomEntry:
|
|||||||
category: Optional[str] = None
|
category: Optional[str] = None
|
||||||
ignore_in_bom: Optional[bool] = False
|
ignore_in_bom: Optional[bool] = False
|
||||||
|
|
||||||
scaled_per_harness = False
|
|
||||||
|
|
||||||
# Used to add all occurence of a BomEntry
|
# Used to add all occurence of a BomEntry
|
||||||
designators: [List] = field(default_factory=list)
|
designators: [List] = field(default_factory=list)
|
||||||
per_harness: [Dict] = field(default_factory=dict)
|
per_harness: [Dict] = field(default_factory=dict)
|
||||||
@ -277,6 +275,10 @@ class BomEntry:
|
|||||||
# Used to restrict printed lengths
|
# Used to restrict printed lengths
|
||||||
MAX_PRINTED_DESCRIPTION: int = 40
|
MAX_PRINTED_DESCRIPTION: int = 40
|
||||||
MAX_PRINTED_DESIGNATORS: int = 2
|
MAX_PRINTED_DESIGNATORS: int = 2
|
||||||
|
restrict_printed_lengths: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
scaled_per_harness = False
|
||||||
|
|
||||||
# Map a bom key to the header
|
# Map a bom key to the header
|
||||||
BOM_KEY_TO_COLUMNS = {
|
BOM_KEY_TO_COLUMNS = {
|
||||||
@ -289,7 +291,7 @@ class BomEntry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
f'{id}: {self.partnumbers}, {self.qty}'
|
return f'{id}: {self.partnumbers}, {self.qty}'
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.partnumbers, self.description))
|
return hash((self.partnumbers, self.description))
|
||||||
@ -344,7 +346,7 @@ class BomEntry:
|
|||||||
@property
|
@property
|
||||||
def description_str(self):
|
def description_str(self):
|
||||||
description = self.description
|
description = self.description
|
||||||
if len(description) > self.MAX_PRINTED_DESCRIPTION:
|
if self.restrict_printed_lengths and len(description) > self.MAX_PRINTED_DESCRIPTION:
|
||||||
description = f"{description[:self.MAX_PRINTED_DESCRIPTION]} (...)"
|
description = f"{description[:self.MAX_PRINTED_DESCRIPTION]} (...)"
|
||||||
return description
|
return description
|
||||||
|
|
||||||
@ -354,7 +356,7 @@ class BomEntry:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
all_designators = sorted(self.designators)
|
all_designators = sorted(self.designators)
|
||||||
if len(all_designators) > self.MAX_PRINTED_DESIGNATORS:
|
if self.restrict_printed_lengths and len(all_designators) > self.MAX_PRINTED_DESIGNATORS:
|
||||||
all_designators = all_designators[: self.MAX_PRINTED_DESIGNATORS] + ["..."]
|
all_designators = all_designators[: self.MAX_PRINTED_DESIGNATORS] + ["..."]
|
||||||
return ", ".join(all_designators)
|
return ", ".join(all_designators)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user