Working resolver, working recursive logic with dynamic library creation

This commit is contained in:
Lyncoln
2026-10-14 01:45:21 -04:00
parent a7cd75cc25
commit e776eddb37
32 changed files with 263 additions and 335 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
#from . import outputs
#from . import managefailure
#from . import savedata
from .select import buildSelect, buildSelect2
from .select import buildSelect
from .outputs import buildOutput
from .savedata import buildSave, loadSave
from .logs import buildLog
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+14 -11
View File
@@ -1,17 +1,20 @@
import logging
def buildLog (action, outputs, response):
#if response.status_code == 200:
#print(f"{action.name} successful")
try:
for print_name, print_key in action.prints.items():
print(
f"{print_name}:",
f"{outputs[print_key]}",
)
if hasattr(action, "prints"):
try:
for print_name, print_key in action.prints.items():
print(
f"{print_name}:",
f"{outputs[print_key]}",
)
except: (KeyError, TypeError)
if action.showstatus is True and response.status_code == 200:
print(f"{action.name} successful")
elif action.showstatus is True and response.status_code != 200:
print(f"{action.name} failed")
#else:
#print(f"{action.name} failed")
except: KeyError, TypeError
return
+11 -11
View File
@@ -3,21 +3,21 @@ def buildOutput(response, action, outputs):#, select_data):
#response_data = select_data
#else:
#response_data = response.json()
response_data = response.json()
response_objects = [response_data]
if hasattr(action, "outputs"):
response_data = response.json()
response_objects = [response_data]
while response_objects:
response_object = response_objects.pop()
while response_objects:
response_object = response_objects.pop()
for key, value, in response_object.items():
for key, value, in response_object.items():
if isinstance(value, dict):
response_objects.append(value)
if isinstance(value, dict):
response_objects.append(value)
for output_name, response_key in action.outputs.items():
if key == response_key:
outputs[output_name] = value
for output_name, response_key in action.outputs.items():
if key == response_key:
outputs[output_name] = value
return outputs
+33
View File
@@ -0,0 +1,33 @@
from core.execution.action.action import buildAction
def recursiveAction(definition, outputs):
recursiveset = definition.recursiveset["actions"]
for item in outputs[definition.recursiveset["source"]]:
outputs[definition.recursiveset["outputlabel"]] = item
#outputs["recursive"] = item
for job in recursiveset:
outputs, response = buildAction(job, outputs)
#outputs[action.recursive["target"]] = item
print(outputs["profile"])
print(outputs["messages"])
return outputs
def recursiveActionStale(action, outputs):
#if hasattr(action, "recursive"):
#outputs[action.recursive["target"]] = {}
for item in outputs[action.recursive["source"]]:
#resolved = resolveItem(action, item)#, outputs)#, resolved)
#print("DEBUG Resolved value:", resolved)
#outputs[action.recursive["target"]] = outputs[action.recursive["source"]][][action.recursive["target"]]
#print(outputs[action.recursive["target"]])
#Target may be phased out here. its not quite necessary after resolve
outputs[action.recursive["target"]] = item
#print(outputs[action.recursive["target"]])
#target = outputs[action.recursive["source"]["target"]
outputs, response = buildAction(action, outputs)#, resolved)
#print(outputs)
return outputs
+39 -13
View File
@@ -1,24 +1,25 @@
def resolveItem(action, item):
resolved = {}
label = action.resolve["label"]
targetkeys = action.resolve["targetkeys"]
if hasattr(action, "resolve"):
#label = action.resolve["label"]
#targetkeys = action.resolve["targetkeys"]
#print(item)
target = item
#target = item
for key in targetkeys:
target = target[key]
#for key in targetkeys:
# target = target[key]
resolved[label] = target
#for label, keys in action.resolve.items():
#target = item
#resolved[label] = target
for label, keys in action.resolve.items():
target = item
#print(item)
#print(target)
#for key in keys:
#target = target[key]
for key in keys:
target = target[key]
#resolved[label] = target
#print(resolved[label])
resolved[label] = target
#print(resolved[label])
return resolved
@@ -47,3 +48,28 @@ def resolveItem2(action, item, outputs):
outputs[label] = target
#print("Resolver DEBUG", target, outputs[label])
return outputs
def resolveItemBackup(action, item):
resolved = {}
if hasattr(action, "resolve"):
#label = action.resolve["label"]
#targetkeys = action.resolve["targetkeys"]
#print(item)
#target = item
#for key in targetkeys:
# target = target[key]
#resolved[label] = target
for label, keys in action.resolve.items():
target = item
#print(item)
#print(target)
for key in keys:
target = target[key]
resolved[label] = target
print(resolved[label])
return resolved
+16 -36
View File
@@ -1,41 +1,21 @@
from core.runtime import buildSelect, buildSelect2, buildOutput, buildSave, buildLog
from core.runtime.select import buildSelect3
#select_data = {}
from core.runtime import buildSelect, buildOutput, buildSave, loadSave, buildLog
#from core.runtime.select import buildSelect3
from core.runtime.resolver import resolveItem
def buildPreRuntimeAttr(action, outputs):
outputs = loadSave(action, outputs)
resolved = resolveItem(action, outputs)
return outputs, resolved
def buildRuntimeAttr(action, outputs, response):
#select_data = {}
#response_data = response.json()
outputs = buildOutput(response, action, outputs)
select_data, action, outputs = buildSelect(action, outputs)
buildSave(action, outputs)
#if hasattr(action, "select"):
#select_data, action, outputs = buildSelect(response, action, outputs)
#else:
#select_data = "not applied"
#print("BEFORE buildOutput:", type(outputs))
if hasattr(action, "outputs"):
outputs = buildOutput(response, action, outputs)#, select_data)
if hasattr(action, "select"):
select_data, action, outputs = buildSelect3(action, outputs)
#print("AFTER buildOutput:", type(outputs))
#print("DEBUG buildSave")
#print("outputs type:", type(outputs))
#print("action type:", type(action))
#print("outputs keys:", list(outputs) if isinstance(outputs, dict) else "NOT A DICT")
if hasattr(action, "savedata"):
buildSave(outputs, action)
if hasattr(action, "prints"):
buildLog(action, outputs, response)
#if hasattr(action, "conversion"):
#conversions = action.conversion.items()
#for key in action.conversion.items():
#print(f"{action.conversion.items[key]}")
#convertedoutput = conversions[key]
#outputs[conversions[key]] = convertedoutput
if action.showstatus is True and response.status_code == 200:
print(f"{action.name} successful")
buildLog(action, outputs, response)
return outputs, response
+15 -15
View File
@@ -1,25 +1,25 @@
import json
def buildSave(outputs, action):
save_data = {}
def buildSave(action, outputs):
if hasattr(action, "savedata"):
save_data = {}
for save_name in action.savedata:
save_data[save_name] = outputs[save_name]
for save_name in action.savedata:
save_data[save_name] = outputs[save_name]
with open(f"{action.savepath}", "w") as save_file:
json.dump(save_data, save_file)
with open(f"{action.savepath}", "w") as save_file:
json.dump(save_data, save_file)
#print(f"{save_name} saved by {action.name}")
print(f"Data saved by {action.name} to {action.savepath}")
print(f"Data saved by {action.name} to {action.savepath}")
return outputs
def loadSave(outputs, action):
with open(f"{action.savepath}", "r") as save_file:
load_data = json.load(save_file)
def loadSave(action, outputs):
if hasattr(action, "loaddata"):
with open(f"{action.savepath}", "r") as save_file:
load_data = json.load(save_file)
for load_name in action.loaddata:
outputs[load_name] = load_data[load_name]
#print(f"{load_name} loaded by {action.name}")
for load_name in action.loaddata:
outputs[load_name] = load_data[load_name]
print(f"Data loaded by {action.name} from {action.savepath}")
print(f"Data loaded by {action.name} from {action.savepath}")
return outputs
+27 -158
View File
@@ -1,165 +1,34 @@
def buildSelect(response, action, outputs):
#if hasattr(action, "select"):
response_data = response.json()
#selection = action.select
#print(response_data)
select_data ={}
for item, index in action.select.items():
select_data[item] = response_data[item][index]
print(select_data)
#if select_data == None:
# selection = "not applied"
#else:
selection = select_data
return selection, action, outputs
def buildSelect2(action, outputs):
#print(outputs)
select_data = []
target = outputs[action.select["source"]]
selectmethod = action.select["selectmethod"]
targetkey = action.select["key"]
targetvalue = action.select["value"]
if isinstance(targetvalue, dict):
for resolvekey, resolveval in targetvalue.items():
print(resolvekey)
print(resolveval)
#outputtarget = outputs[resolvekey]
#for thing in resolveval:
outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
print (outputtarget)
targetvalue = outputtarget
#for item in target:
for item in target:
#print (item)
for key, value in item.items():
#if isinstance(targetvalue, dict):
#for resolvekey, resolveval in targetvalue.items():
#print(resolvekey)
#print(resolveval)
#outputtarget = outputs[resolvekey]
#for thing in resolveval:
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
#print (outputtarget)
#outputtarget = targetvalue
if selectmethod == "exclude":
if targetkey == key and item[key] != targetvalue:
select_data.append(item)
#print(item)
if selectmethod == "include":
if targetkey == key and item[key] == targetvalue:
select_data.append(item)
#print(item)
outputs[action.select["source"]] = select_data
#print(outputs)
return select_data, action, outputs
#for item in outputs[output_name]:
#for key, value in action.select.include.items():
#if key in item and item[key] == value:
#select_data.append(item)
def buildSelect3(action, outputs):
#print(outputs)
try:
select_data = []
target = outputs[action.select["source"]]
includekey = action.select["include"]["key"]
includevalue = action.select["include"]["value"]
excludekey = action.select["exclude"]["key"]
excludevalue = action.select["exclude"]["value"]
for item in target:
include_match = True
exclude_match = True
if includekey:
include_match = item[includekey] == includevalue
if excludekey:
exclude_match = item[excludekey] != excludevalue
if include_match and exclude_match:
select_data.append(item)
outputs[action.select["source"]] = select_data
print(select_data)
return select_data, action, outputs
except (KeyError, TypeError):
return select_data, action, outputs
def buildSelect4(action, outputs):
#print(outputs)
def buildSelect(action, outputs):
#***THIS IS THE CANONICAL BUILD***
select_data = []
target = outputs[action.select["source"]]
#selectmethod = action.select["selectmethod"]
includekey = action.select["include"]["key"]
includevalue = action.select["include"]["value"]
excludekey = action.select["exclude"]["key"]
excludevalue = action.select["exclude"]["value"]
#if isinstance(targetvalue, dict):
#for resolvekey, resolveval in targetvalue.items():
#print(resolvekey)
#print(resolveval)
#outputtarget = outputs[resolvekey]
#for thing in resolveval:
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
#print (outputtarget)
#targetvalue = outputtarget
#for item in target:
#include_match = True
#exclude_match = True
if hasattr(action, "select"):
try:
target = outputs[action.select["source"]]
includekey = action.select["include"]["key"]
includevalue = action.select["include"]["value"]
excludekey = action.select["exclude"]["key"]
excludevalue = action.select["exclude"]["value"]
for item in target:
include_match = True
exclude_match = True
for item in target:
include_match = True
exclude_match = True
if includekey:
include_match = item[includekey] == includevalue
if includekey:
include_match = item[includekey] == includevalue
if excludekey:
exclude_match = item[excludekey] != excludevalue
if excludekey:
exclude_match = item[excludekey] != excludevalue
if include_match and exclude_match:
select_data.append(item)
#print (item)
#for key, value in item.items():
#if isinstance(targetvalue, dict):
#for resolvekey, resolveval in targetvalue.items():
#print(resolvekey)
#print(resolveval)
#outputtarget = outputs[resolvekey]
#for thing in resolveval:
#outputtarget = outputs[resolvekey][resolveval[0]][resolveval[1]]
#print (outputtarget)
#outputtarget = targetvalue
#if selectmethod == "exclude":
#if item[excludekey] != excludevalue:# and item[includekey] == includevalue:
#if includekey == key and item[key] == includevalue:
#if item[excludekey] == excludevalue:
#continue
#select_data.append(item)
#if item[includekey] == includevalue:
#if includekey == key and item[key] == includevalue:
#continue
#select_data.append(item)
#if excludekey == key and item[key] != excludevalue:
#select_data.append(item)
#print(item)
#if selectmethod == "include":
#if excludekey == key and item[key] == excludevalue:
#select_data.append(item)
#print(item)
outputs[action.select["source"]] = select_data
print(select_data)
if include_match and exclude_match:
select_data.append(item)
outputs[action.select["source"]] = select_data
#print(select_data)
return select_data, action, outputs
except (KeyError, TypeError):
select_data = ["no selection"]
return select_data, action, outputs
+21
View File
@@ -0,0 +1,21 @@
def skipStep(definition, action, outputs):
if hasattr(definition, "skipstep"):
try:
if action in definition.skipstep:
condition = definition.skipstep[action]
#if outputs.get([condition["output"]]) is None:
#return False
#current_value = 1
#else:
current_value = outputs[condition["output"]]
#current_value = 1
if condition["operator"] == ">=":
if current_value >= condition["value"]:
print(f"Skipping {action.name}")
return True
except KeyError:
#outputs = manageFailure(error)
return False