From: Keith Packard Date: Tue, 11 Feb 2025 04:31:40 +0000 (-0800) Subject: bin: Do case-insensitive matching for preferred parts X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d7ab2d7a30c05be6e9ca5e562660ad3d8a2dfe19;p=hw%2Faltusmetrum bin: Do case-insensitive matching for preferred parts This covers MHz vs mhz and other case-changes. Signed-off-by: Keith Packard --- diff --git a/bin/parts.py b/bin/parts.py index 3b6321a..3da77e3 100644 --- a/bin/parts.py +++ b/bin/parts.py @@ -36,7 +36,7 @@ key_attrs = ('device', 'value', 'footprint') pref_order = ('device', 'value', 'footprint', 'loadstatus', 'provided', 'mfg', 'mfg_part_number', 'vendor', 'vendor_part_number', 'quantity', 'refdes') -value_pattern=r'([0-9]+)(\.[0-9]*)?([kmMupng]?)(F|H|Hz)?' +value_pattern=r'([0-9]+)(\.[0-9]*)?([kmMupng]?)(F|H|Hz|V|screws)?([ _][0-9]+(\.[0-9]*))?' class Part(): """ @@ -62,6 +62,12 @@ class Part(): return self.attrs[attr] return None + # Get an attribute value in lower case + def get_lower(self, attr): + if attr in self.attrs: + return self.attrs[attr].lower() + return None + # Get an attribute value, returning 'unknown' for # missing attributes def get_unknown(self, attr): @@ -85,7 +91,7 @@ class Part(): # Compute the key tuple (device, value, footprint) def key(self): - return tuple(map(self.get, key_attrs)) + return tuple(map(self.get_lower, key_attrs)) # Return a set of all attributes in the part def attrs_set(self): @@ -101,12 +107,11 @@ class Part(): return str(self.attrs) class Parts(): - """ - A parts list, indexed by the part key (dice, value, footprint) + A parts list, indexed by the part key (device, value, footprint) """ - csv_dialect = csv.register_dialect('excel-nl', 'excel', lineterminator='\n') + csv.register_dialect('excel-nl', 'excel', lineterminator='\n') def __init__(self, parts=None, ods=None, csv=None, csv_file=None, tab=None, tab_file=None): if parts is not None: