]> git.gag.com Git - hw/altusmetrum/commitdiff
bin: Do case-insensitive matching for preferred parts
authorKeith Packard <keithp@keithp.com>
Tue, 11 Feb 2025 04:31:40 +0000 (20:31 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 11 Feb 2025 04:31:40 +0000 (20:31 -0800)
This covers MHz vs mhz and other case-changes.

Signed-off-by: Keith Packard <keithp@keithp.com>
bin/parts.py

index 3b6321ae5b30ba5b4af2b3479c79ccc7de4f9cd6..3da77e3afae9289acd0a80b5036f5030ad17f69e 100644 (file)
@@ -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: