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