From a52f96b7e449eb7040c554eff0871f6de47a83b9 Mon Sep 17 00:00:00 2001 From: Roman Dobrodii Date: Mon, 24 Aug 2020 12:40:36 +0200 Subject: [PATCH 1/4] Fix variant logic for '+'-prefixed board variants --- kibom/component.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/kibom/component.py b/kibom/component.py index 9dbe064..9dfd9d6 100644 --- a/kibom/component.py +++ b/kibom/component.py @@ -108,7 +108,7 @@ def __eq__(self, other): """ Equivalency operator is used to determine if two parts are 'equal' """ - + # 'fitted' value must be the same for both parts if self.isFitted() != other.isFitted(): return False @@ -144,7 +144,7 @@ def getPrefix(self): Get the reference prefix e.g. if this component has a reference U12, will return "U" """ - + prefix = "" for c in self.getRef(): @@ -160,7 +160,7 @@ def getSuffix(self): Return the reference suffix # e.g. if this component has a reference U12, will return "12" """ - + suffix = "" for c in self.getRef(): @@ -298,13 +298,13 @@ def getFieldNames(self): """ fieldNames = [] - + fields = self.element.getChild('fields') - + if fields: for f in fields.getChildren(): fieldNames.append(f.get('field', 'name')) - + return fieldNames def getRef(self): @@ -328,21 +328,26 @@ def isFitted(self): if opt.lower() in DNF: return False - # Variants logic - opts = check.split(",") + # Variants logic (comma-separated list) + opts = [s.strip() for s in check.split(",")] + + # Negative decisions for opt in opts: - opt = opt.strip() # Any option containing a DNF is not fitted if opt in DNF: return False # Options that start with '-' are explicitly removed from certain configurations - if opt.startswith("-") and str(opt[1:]) in self.prefs.pcbConfig: + if opt.startswith("-") and opt[1:] in self.prefs.pcbConfig: return False + + # Positive decisions + for opt in opts: # Options that start with '+' are fitted only for certain configurations - if opt.startswith("+") and opt[1:] not in self.prefs.pcbConfig: - return False + if opt.startswith("+") and opt[1:] in self.prefs.pcbConfig: + return True - return True + # If no decision has been made, component is not fitted + return False def isFixed(self): """ Determine if a component is FIXED or not. @@ -455,7 +460,7 @@ def add(self, P, N): self.stack.append(((P, N), (P, N))) def flush(self, sep, N=None, dash='-'): - + refstr = u'' c = 0 @@ -499,10 +504,10 @@ def getField(self, field): if field not in self.fields.keys(): return "" - + if not self.fields[field]: return "" - + return u''.join((self.fields[field])) def getCount(self): From afb06f96db7e1299461a7b391f9bb74fc03af8e2 Mon Sep 17 00:00:00 2001 From: Roman Dobrodii Date: Mon, 24 Aug 2020 17:02:38 +0200 Subject: [PATCH 2/4] Restore ws --- kibom/component.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kibom/component.py b/kibom/component.py index 9dfd9d6..5660fa4 100644 --- a/kibom/component.py +++ b/kibom/component.py @@ -108,7 +108,7 @@ def __eq__(self, other): """ Equivalency operator is used to determine if two parts are 'equal' """ - + # 'fitted' value must be the same for both parts if self.isFitted() != other.isFitted(): return False @@ -144,7 +144,7 @@ def getPrefix(self): Get the reference prefix e.g. if this component has a reference U12, will return "U" """ - + prefix = "" for c in self.getRef(): @@ -160,7 +160,7 @@ def getSuffix(self): Return the reference suffix # e.g. if this component has a reference U12, will return "12" """ - + suffix = "" for c in self.getRef(): @@ -298,13 +298,13 @@ def getFieldNames(self): """ fieldNames = [] - + fields = self.element.getChild('fields') - + if fields: for f in fields.getChildren(): fieldNames.append(f.get('field', 'name')) - + return fieldNames def getRef(self): @@ -460,7 +460,7 @@ def add(self, P, N): self.stack.append(((P, N), (P, N))) def flush(self, sep, N=None, dash='-'): - + refstr = u'' c = 0 @@ -504,10 +504,10 @@ def getField(self, field): if field not in self.fields.keys(): return "" - + if not self.fields[field]: return "" - + return u''.join((self.fields[field])) def getCount(self): From 15cd7feb1bdf2b39c3570bfbe28dc2ccf953281d Mon Sep 17 00:00:00 2001 From: Roman Dobrodii Date: Mon, 24 Aug 2020 17:46:57 +0200 Subject: [PATCH 3/4] Fix logic --- kibom/component.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/kibom/component.py b/kibom/component.py index 5660fa4..52b9483 100644 --- a/kibom/component.py +++ b/kibom/component.py @@ -330,24 +330,26 @@ def isFitted(self): # Variants logic (comma-separated list) opts = [s.strip() for s in check.split(",")] - - # Negative decisions - for opt in opts: - # Any option containing a DNF is not fitted - if opt in DNF: - return False - # Options that start with '-' are explicitly removed from certain configurations - if opt.startswith("-") and opt[1:] in self.prefs.pcbConfig: + included_configs = set(opt[1:] for opt in opts if opt.startswith("+")) + excluded_configs = set(opt[1:] for opt in opts if opt.startswith("-")) + + # Logic here: + # - If pcbConfig specifies variant from excluded_configs, component + # is excluded. + # - Otherwise, if included_configs is empty, component is included. + # - Otherwise, component is included only if pcbConfig specifies + # variant which is a member of included_configs. + + included = True + if included_configs: + included = False + for config in self.prefs.pcbConfig: + if config in excluded_configs: return False - - # Positive decisions - for opt in opts: - # Options that start with '+' are fitted only for certain configurations - if opt.startswith("+") and opt[1:] in self.prefs.pcbConfig: - return True - - # If no decision has been made, component is not fitted - return False + if config in included_configs: + included = True + + return included def isFixed(self): """ Determine if a component is FIXED or not. From e6da86cc607c34071c19da429020d033ba221e30 Mon Sep 17 00:00:00 2001 From: Roman Dobrodii Date: Sun, 20 Sep 2020 13:10:47 +0200 Subject: [PATCH 4/4] Fix: restore missing check for DNF keyword in comma-separated options list --- kibom/component.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kibom/component.py b/kibom/component.py index 52b9483..62d3fa9 100644 --- a/kibom/component.py +++ b/kibom/component.py @@ -330,9 +330,15 @@ def isFitted(self): # Variants logic (comma-separated list) opts = [s.strip() for s in check.split(",")] + + # Exclude this component if any form of "DNF" keyword is listed in options + for opt in opts: + if opt.lower() in DNF: + return False + included_configs = set(opt[1:] for opt in opts if opt.startswith("+")) excluded_configs = set(opt[1:] for opt in opts if opt.startswith("-")) - + # Logic here: # - If pcbConfig specifies variant from excluded_configs, component # is excluded.