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/kicad/functions.py | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) (limited to 'src/ee/kicad') diff --git a/src/ee/kicad/functions.py b/src/ee/kicad/functions.py index c0d1780..a2f9f80 100644 --- a/src/ee/kicad/functions.py +++ b/src/ee/kicad/functions.py @@ -1,10 +1,8 @@ import re -import yaml import ee.kicad.model import ee.kicad.sch_fact_types as kicad_ft -from ee import EeException from ee.kicad import sch_fact_types from ee.part import Part from ee.part import common_fact_types @@ -109,38 +107,10 @@ def mpn_strategy(**kwargs): # noinspection PyUnusedLocal def map_footprint(footprint_mappings=None, **kwargs): - if footprint_mappings is None: - return None + # noinspection PyProtectedMember + from ee.part._utils import map_footprint - 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 "kicad-to-common" not in doc: - raise EeException("The footprint mappings document must contain the key 'kicad-to-common'.") - - for k, v in doc["kicad-to-common"].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: - kicad_footprint = part.facts.get_value(kicad_ft.footprint) - - if not kicad_footprint: - return part - - footprint = mappings.get(kicad_footprint, None) - - if footprint: - part.facts.add(common_fact_types.footprint, footprint) - - return part - - return on_part + return map_footprint(footprint_mappings, "kicad-to-common", kicad_ft.footprint) def default(**kwargs): -- cgit v1.2.3