Files
rmmanager/core/runtime/resolver.py
T

83 lines
2.8 KiB
Python

def resolveItem(action, item):
resolved = {}
if hasattr(action, "resolve"):
for label, keys in action.resolve["get"].items():
target = item
for key in keys:
target = target.get(key)
#target = target[key]
resolved[label] = target
if "construct" in action.resolve:
for label2, piece in action.resolve["construct"].items():
constructed = ""
for item in piece:
if isinstance(item, dict):
for key, value in item.items():
item = resolved[value]
constructed += str(item)
resolved[label2] = constructed
if "transform" in action.resolve:
for source, mutation in action.resolve["transform"].items():
for key, value in mutation.items():
if resolved[source] == key:
resolved[source] = value
if "deconstruct" in action.resolve:
for source, mutation in action.resolve["deconstruct"].items():
deconstructed = str(resolved[source])
for item in mutation:
deconstructed = deconstructed.replace(str(item), "")
resolved[source] = deconstructed
return resolved
def resolveItem2(action, item):
resolved = {}
if hasattr(action, "resolve"):
for label, keys in action.resolve["get"].items():
target = item
for key in keys:
target = target[key]
resolved[label] = target
for mutation in action.resolve.get("mutate", []):
if "construct" in mutation:
for label2, piece in mutation["construct"].items():
constructed = ""
for part in piece:
if isinstance(part, dict):
for key, value in part.items():
part = resolved[value]
constructed += str(part)
resolved[label2] = constructed
elif "transform" in mutation:
for source, transformation in mutation["transform"].items():
for key, value in transformation.items():
if resolved[source] == key:
resolved[source] = value
elif "deconstruct" in mutation:
for source, change in mutation["deconstruct"].items():
deconstructed = str(resolved[source])
for removal in change:
deconstructed = deconstructed.replace(str(removal), "")
resolved[source] = deconstructed
return resolved