aboutsummaryrefslogtreecommitdiff
path: root/src/ee/part
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/part')
-rw-r--r--src/ee/part/_utils.py38
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