diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-21 07:57:12 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-21 07:57:12 +0200 |
commit | c8c04a73fef2e2f365d448a067bc5a6c8b20bebb (patch) | |
tree | 1db4475641dc6f8b914e4940145be86e2a167c80 /src/ee/part | |
parent | 9bbb4f8f3a1d8e2bfe1f06c945081153435de940 (diff) | |
download | ee-python-c8c04a73fef2e2f365d448a067bc5a6c8b20bebb.tar.gz ee-python-c8c04a73fef2e2f365d448a067bc5a6c8b20bebb.tar.bz2 ee-python-c8c04a73fef2e2f365d448a067bc5a6c8b20bebb.tar.xz ee-python-c8c04a73fef2e2f365d448a067bc5a6c8b20bebb.zip |
o Creating a map_footprints function for digikey's footprints similar to
kicad's function.
Diffstat (limited to 'src/ee/part')
-rw-r--r-- | src/ee/part/_utils.py | 38 |
1 files changed, 38 insertions, 0 deletions
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 |