Skip to content

Commit

Permalink
Merge pull request #115 from INTI-CMNB/join_fields_2
Browse files Browse the repository at this point in the history
Added "join" to join fields like voltage, current, etc. with the value
  • Loading branch information
SchrodingersGat committed Jul 18, 2020
2 parents f970fce + e33cb05 commit c36f55d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kibom/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,18 @@ def getRow(self, columns):
for key in columns:
val = self.getField(key)

# Join fields (appending to current value) (#81)
for join_l in self.prefs.join:
# Each list is "target, source..." so we need at least 2 elements
elements = len(join_l)
target = join_l[0]
if elements > 1 and target == key:
# Append data from the other fields
for source in join_l[1:]:
v = self.getField(source)
if v:
val = val + ' ' + v

if val is None:
val = ""
else:
Expand Down
19 changes: 19 additions & 0 deletions kibom/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class BomPref:
SECTION_GROUPING_FIELDS = "GROUP_FIELDS"
SECTION_REGEXCLUDES = "REGEX_EXCLUDE"
SECTION_REGINCLUDES = "REGEX_INCLUDE"
SECTION_JOIN = "JOIN" # (#81)

OPT_DIGIKEY_LINK = "digikey_link"
OPT_PCB_CONFIG = "pcb_configuration"
Expand Down Expand Up @@ -105,6 +106,9 @@ def __init__(self):
["d", "diode", "d_small"]
]

# Nothing to join by default (#81)
self.join = []

# Check an option within the SECTION_GENERAL group
def checkOption(self, parser, opt, default=False):
if parser.has_option(self.SECTION_GENERAL, opt):
Expand Down Expand Up @@ -183,6 +187,10 @@ def Read(self, file, verbose=False):
if self.SECTION_ALIASES in cf.sections():
self.aliases = [re.split('[ \t]+', a) for a in cf.options(self.SECTION_ALIASES)]

# Read out join rules (#81)
if self.SECTION_JOIN in cf.sections():
self.join = [a.split('\t') for a in cf.options(self.SECTION_JOIN)]

if self.SECTION_REGEXCLUDES in cf.sections():
self.regExcludes = []
for pair in cf.options(self.SECTION_REGEXCLUDES):
Expand Down Expand Up @@ -279,6 +287,17 @@ def Write(self, file):
for a in self.aliases:
cf.set(self.SECTION_ALIASES, "\t".join(a))

# (#81)
cf.add_section(self.SECTION_JOIN)
cf.set(self.SECTION_JOIN, '; A list of rules to join the content of fields')
cf.set(self.SECTION_JOIN, '; Each line is a rule, the first name is the field that will receive the data')
cf.set(self.SECTION_JOIN, '; from the other fields')
cf.set(self.SECTION_JOIN, '; Use tab (ASCII 9) as separator')
cf.set(self.SECTION_JOIN, '; Field names are case sensitive')

for a in self.join:
cf.set(self.SECTION_JOIN, "\t".join(a))

cf.add_section(self.SECTION_REGINCLUDES)
cf.set(self.SECTION_REGINCLUDES, '; A series of regular expressions used to include parts in the BoM')
cf.set(self.SECTION_REGINCLUDES, '; If there are any regex defined here, only components that match against ANY of them will be included in the BOM')
Expand Down

0 comments on commit c36f55d

Please sign in to comment.