Made app_sdk loop parser more stable. Still missing recursion.

This commit is contained in:
frikky
2020-06-27 08:02:29 +02:00
parent 366d14a3e8
commit dfc639c92b
2 changed files with 84 additions and 30 deletions
+15 -9
View File
@@ -340,7 +340,7 @@ class AppBase:
#print("WF Variables: %s" % execution_data["workflow"]["workflow_variables"]) #print("WF Variables: %s" % execution_data["workflow"]["workflow_variables"])
for variable in execution_data["workflow"]["workflow_variables"]: for variable in execution_data["workflow"]["workflow_variables"]:
variablename = variable["name"].replace(" ", "_", -1).lower() variablename = variable["name"].replace(" ", "_", -1).lower()
if variablename.lower() == actionname_lower: if variablename.lower() == actionname_lower:
baseresult = variable["value"] baseresult = variable["value"]
break break
@@ -350,7 +350,7 @@ class AppBase:
except TypeError as e: except TypeError as e:
print("TypeError wf variables: %s" % e) print("TypeError wf variables: %s" % e)
pass pass
print("BEFORE EXECUTION VAR") print("BEFORE EXECUTION VAR")
if len(baseresult) == 0: if len(baseresult) == 0:
try: try:
@@ -386,18 +386,20 @@ class AppBase:
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
return baseresult return baseresult
# This whole thing should be recursive.
try: try:
cnt = 0 cnt = 0
for value in parsersplit[1:]: for value in parsersplit[1:]:
cnt += 1 cnt += 1
print("VALUE: %s" % value)
if value == "#": if value == "#":
# FIXME - not recursive - should go deeper if there are more # # FIXME - not recursive - should go deeper if there are more #
print("HANDLE RECURSIVE LOOP OF %s" % basejson) print("HANDLE RECURSIVE LOOP OF %s" % basejson)
returnlist = [] returnlist = []
try: try:
for innervalue in basejson: for innervalue in basejson:
print("Value: %s" % value[parsersplit[cnt+1]]) print("Value: %s" % innervalue[parsersplit[cnt+1]])
returnlist.append(innervalue[parsersplit[cnt+1]]) returnlist.append(innervalue[parsersplit[cnt+1]])
except IndexError as e: except IndexError as e:
print("Indexerror inner: %s" % e) print("Indexerror inner: %s" % e)
@@ -406,12 +408,11 @@ class AppBase:
indexvalue = "${NO_SPLITTER%s}$" % json.dumps(basejson) indexvalue = "${NO_SPLITTER%s}$" % json.dumps(basejson)
if len(returnlist) > 0: if len(returnlist) > 0:
indexvalue = "${NO_SPLITTER%s}$" % json.dumps(returnlist) indexvalue = "${NO_SPLITTER%s}$" % json.dumps(returnlist)
print("INDEXVAL: ", indexvalue) print("INDEXVAL: ", indexvalue)
return indexvalue return indexvalue
except TypeError as e: except TypeError as e:
print("Inner TypeError: %s" % e) print("TypeError inner: %s" % e)
return basejson
# Example format: ${[]}$ # Example format: ${[]}$
parseditem = "${%s%s}$" % (parsersplit[cnt+1], json.dumps(returnlist)) parseditem = "${%s%s}$" % (parsersplit[cnt+1], json.dumps(returnlist))
@@ -419,6 +420,10 @@ class AppBase:
return parseditem return parseditem
else: else:
print("BEFORE NORMAL VALUE: ", basejson, value)
if len(value) == 0:
return basejson
if isinstance(basejson[value], str): if isinstance(basejson[value], str):
print(f"LOADING STRING '%s' AS JSON" % basejson[value]) print(f"LOADING STRING '%s' AS JSON" % basejson[value])
try: try:
@@ -432,8 +437,9 @@ class AppBase:
except KeyError as e: except KeyError as e:
print("Lower keyerror: %s" % e) print("Lower keyerror: %s" % e)
return "KeyError: Couldn't find key: %s" % e return "KeyError: Couldn't find key: %s" % e
return basejson return basejson
def parse_params(action, fullexecution, parameter): def parse_params(action, fullexecution, parameter):
@@ -442,7 +448,7 @@ class AppBase:
# Matches with space in the first part, but not in subsequent parts. # Matches with space in the first part, but not in subsequent parts.
# JSON / yaml etc shouldn't have spaces in their fields anyway. # JSON / yaml etc shouldn't have spaces in their fields anyway.
match = ".*?([$]{1}([a-zA-Z0-9 _-]+\.?){1}([a-zA-Z0-9_-]+\.?){0,})" match = ".*?([$]{1}([a-zA-Z0-9 _-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,})"
# Regex to find all the things # Regex to find all the things
if parameter["variant"] == "STATIC_VALUE": if parameter["variant"] == "STATIC_VALUE":
File diff suppressed because one or more lines are too long