From c8c04a73fef2e2f365d448a067bc5a6c8b20bebb Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 21 May 2019 07:57:12 +0200 Subject: o Creating a map_footprints function for digikey's footprints similar to kicad's function. --- src/ee/part/_utils.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/ee/part/_utils.py (limited to 'src/ee/part') diff --git a/src/ee/part/_utils.py b/src/ee/part/_utils.py new file mode 100644 index 0000000..4b54f6e --- /dev/null +++ b/src/ee/part/_utils.py @@ -0,0 +1,38 @@ +import yaml +from ee import EeException +from ee.part import Part, common_fact_types + + +def map_footprint(footprint_mappings, table, from_footprint_key): + if footprint_mappings is None: + return None + + mappings = {} + with open(footprint_mappings, "r") as f: + doc = yaml.load(f, Loader=yaml.SafeLoader) + if not isinstance(doc, dict): + raise EeException("The footprint mappings document must be a dict.") + + if table not in doc: + raise EeException("The footprint mappings document must contain the key '{}'.".format(table)) + + for k, v in doc[table].items(): + if not isinstance(v, str): + raise EeException("Bad value for key {}, must be a string".format(k)) + + mappings[k] = v + + def on_part(part: Part) -> Part: + from_footprint = part.facts.get_value(from_footprint_key) + + if not from_footprint: + return part + + footprint = mappings.get(from_footprint, None) + + if footprint: + part.facts.add(common_fact_types.footprint, footprint) + + return part + + return on_part -- cgit v1.2.3