aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ee/digikey/functions.py9
-rw-r--r--src/ee/kicad/functions.py36
-rw-r--r--src/ee/part/_utils.py38
3 files changed, 50 insertions, 33 deletions
diff --git a/src/ee/digikey/functions.py b/src/ee/digikey/functions.py
index 047fad1..c902b71 100644
--- a/src/ee/digikey/functions.py
+++ b/src/ee/digikey/functions.py
@@ -140,9 +140,18 @@ def normalize_facts(**kwargs):
return on_part
+# noinspection PyUnusedLocal
+def map_footprint(footprint_mappings=None, **kwargs):
+ # noinspection PyProtectedMember
+ from ee.part._utils import map_footprint
+
+ return map_footprint(footprint_mappings, "digikey-to-common", uris.make_digikey_fact_key(16))
+
+
def default(**kwargs):
function_factories = [
normalize_facts,
+ map_footprint,
]
functions = [factory(**kwargs) for factory in function_factories]
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):
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