Removed custom handler for SHUFFLE_NO_SPLITTER loop handler and further debug logs

This commit is contained in:
Frikky
2024-04-29 13:00:12 +02:00
parent 5e789d4a53
commit 45a6089629
+1 -104
View File
@@ -2526,7 +2526,7 @@ class AppBase:
return template return template
if "${" in template and "}$" in template: if "${" in template and "}$" in template:
self.logger.info("[DEBUG] Shuffle loop shouldn't run in liquid. Data length: %d" % len(template)) #self.logger.info("[DEBUG] Shuffle loop shouldn't run in liquid. Data length: %d" % len(template))
return template return template
@@ -3436,103 +3436,7 @@ class AppBase:
handled = False handled = False
# Has a loop without a variable used inside # Has a loop without a variable used inside
if len(actualitem[0]) > 2 and actualitem[0][1] == "SHUFFLE_NO_SPLITTER":
tmpitem = value
#index = 0
for index in range(len(actualitem)):
# Check if it's SHUFFLE_NO_SPLITTER
if actualitem[index][1] != "SHUFFLE_NO_SPLITTER":
continue
replacement = actualitem[index][2]
if replacement.endswith("}$"):
replacement = replacement[:-2]
if replacement.startswith("\"") and replacement.endswith("\""):
replacement = replacement[1:len(replacement)-1]
#json_replacement = tmpitem.replace(actualitem[index][0], replacement, 1)
json_replacement = replacement
try:
json_replacement = json.loads(replacement)
except json.decoder.JSONDecodeError as e:
try:
replacement = replacement.replace("\'", "\"", -1)
json_replacement = json.loads(replacement)
except:
self.logger.info("JSON error singular: %s" % e)
if len(json_replacement) > minlength:
minlength = len(json_replacement)
new_replacement = []
for i in range(len(json_replacement)):
if isinstance(json_replacement[i], dict) or isinstance(json_replacement[i], list):
tmp_replacer = json.dumps(json_replacement[i])
newvalue = tmpitem.replace(str(actualitem[index][0]), str(tmp_replacer), 1)
else:
newvalue = tmpitem.replace(str(actualitem[index][0]), str(json_replacement[i]), 1)
try:
newvalue = parse_liquid(newvalue, self)
except Exception as e:
self.logger.info(f"[WARNING] Failed liquid parsing in loop (2): {e}")
tmpitem = str(newvalue)
try:
newvalue = json.loads(newvalue)
except json.decoder.JSONDecodeError as e:
pass
# The list to use for the multi execution IF not a file list
new_replacement.append(newvalue)
# FIXME: Should this use new_replacement?
tmpitem = tmpitem.replace(actualitem[index][0], replacement, 1)
# This code handles files.
resultarray = []
isfile = False
try:
if parameter["schema"]["type"] == "file" and len(value) > 0:
self.logger.info("(1) SHOULD HANDLE FILE IN MULTI. Get based on value %s" % tmpitem)
# This is silly :)
# Q: Is there something wrong with the download system?
# It seems to return "FILE CONTENT: %s" with the ID as %s
for tmp_file_split in json.loads(tmpitem):
file_value = self.get_file(tmp_file_split)
resultarray.append(file_value)
isfile = True
except NameError as e:
self.logger.info("(1) SCHEMA NAMEERROR IN FILE HANDLING: %s" % e)
except KeyError as e:
self.logger.info("(1) SCHEMA KEYERROR IN FILE HANDLING: %s" % e)
except json.decoder.JSONDecodeError as e:
self.logger.info("(1) JSON ERROR IN FILE HANDLING: %s" % e)
if not isfile:
# Should be here in normal circumstances
params[parameter["name"]] = tmpitem
multi_parameters[parameter["name"]] = new_replacement
else:
params[parameter["name"]] = resultarray
multi_parameters[parameter["name"]] = resultarray
#if len(resultarray) == 0:
# self.logger.info("[WARNING] Returning empty array because the array length to be looped is 0 (1)")
# action_result["status"] = "SUCCESS"
# action_result["result"] = "[]"
# self.send_result(action_result, headers, stream_path)
# return
multi_execution_lists.append(new_replacement)
#self.logger.info("MULTI finished: %s" % json_replacement)
else:
# This is here to handle for loops within variables.. kindof # This is here to handle for loops within variables.. kindof
# 1. Find the length of the longest array # 1. Find the length of the longest array
# 2. Build an array with the base values based on parameter["value"] # 2. Build an array with the base values based on parameter["value"]
@@ -3551,10 +3455,6 @@ class AppBase:
self.logger.info("[WARNING] Indexerror") self.logger.info("[WARNING] Indexerror")
continue continue
#self.logger.info(f"\n\nTMPITEM: {actualitem}\n\n")
#actualitem = parse_wrapper_start(actualitem)
#self.logger.info(f"\n\nTMPITEM2: {actualitem}\n\n")
try: try:
itemlist = json.loads(actualitem) itemlist = json.loads(actualitem)
if len(itemlist) > minlength: if len(itemlist) > minlength:
@@ -3570,8 +3470,6 @@ class AppBase:
# Parses the data as string with length, split etc. before moving on. # Parses the data as string with length, split etc. before moving on.
#self.logger.info("In second part of else: %s" % (len(itemlist))) #self.logger.info("In second part of else: %s" % (len(itemlist)))
# This is a result array for JUST this value.. # This is a result array for JUST this value..
# What if there are more? # What if there are more?
@@ -3662,7 +3560,6 @@ class AppBase:
self.logger.info("SCHEMA ERROR IN FILE HANDLING: %s" % e) self.logger.info("SCHEMA ERROR IN FILE HANDLING: %s" % e)
#remove_params.append(parameter["name"])
# Fix lists here # Fix lists here
# FIXME: This doesn't really do anything anymore # FIXME: This doesn't really do anything anymore
#self.logger.info("[DEBUG] CHECKING multi execution list: %d!" % len(multi_execution_lists)) #self.logger.info("[DEBUG] CHECKING multi execution list: %d!" % len(multi_execution_lists))