Introduced error management to prevent crashes and added prints for error reporting during runtime
This commit is contained in:
@@ -3,12 +3,16 @@ def resolveItem(action, item):
|
|||||||
if hasattr(action, "resolve"):
|
if hasattr(action, "resolve"):
|
||||||
for label, keys in action.resolve["get"].items():
|
for label, keys in action.resolve["get"].items():
|
||||||
target = item
|
target = item
|
||||||
|
try:
|
||||||
|
for key in keys:
|
||||||
|
target = target[key]
|
||||||
|
|
||||||
for key in keys:
|
except (KeyError, IndexError) as error:
|
||||||
target = target.get(key)
|
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||||
#target = target[key]
|
target = None
|
||||||
|
|
||||||
resolved[label] = target
|
resolved[label] = target
|
||||||
|
|
||||||
if "construct" in action.resolve:
|
if "construct" in action.resolve:
|
||||||
for label2, piece in action.resolve["construct"].items():
|
for label2, piece in action.resolve["construct"].items():
|
||||||
constructed = ""
|
constructed = ""
|
||||||
@@ -21,6 +25,7 @@ def resolveItem(action, item):
|
|||||||
constructed += str(item)
|
constructed += str(item)
|
||||||
|
|
||||||
resolved[label2] = constructed
|
resolved[label2] = constructed
|
||||||
|
|
||||||
if "transform" in action.resolve:
|
if "transform" in action.resolve:
|
||||||
for source, mutation in action.resolve["transform"].items():
|
for source, mutation in action.resolve["transform"].items():
|
||||||
for key, value in mutation.items():
|
for key, value in mutation.items():
|
||||||
@@ -81,3 +86,55 @@ def resolveItem2(action, item):
|
|||||||
resolved[source] = deconstructed
|
resolved[source] = deconstructed
|
||||||
|
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
|
def extractItem(action, item, resolved):
|
||||||
|
if hasattr(action, "extract"):
|
||||||
|
for label, keys in action.extract["get"].items():
|
||||||
|
#resolved[label] = {}
|
||||||
|
target = item
|
||||||
|
try:
|
||||||
|
for key in keys:
|
||||||
|
#if isinstance(target, dict):
|
||||||
|
#.get not compatible with resolving through lists
|
||||||
|
#target = target.get(key)
|
||||||
|
|
||||||
|
#if isinstance(target, list):
|
||||||
|
#regular key not compatible with resolving potentially unknown values like upload image
|
||||||
|
target = target[key]
|
||||||
|
|
||||||
|
except (KeyError, IndexError) as error:
|
||||||
|
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||||
|
target = None
|
||||||
|
|
||||||
|
print("EXTRACT MODULE TEST")
|
||||||
|
print(target)
|
||||||
|
resolved[label] = target
|
||||||
|
if "construct" in action.extract:
|
||||||
|
for label2, piece in action.extract["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.extract:
|
||||||
|
for source, mutation in action.extract["transform"].items():
|
||||||
|
for key, value in mutation.items():
|
||||||
|
if resolved[source] == key:
|
||||||
|
resolved[source] = value
|
||||||
|
|
||||||
|
if "deconstruct" in action.extract:
|
||||||
|
for source, mutation in action.extract["deconstruct"].items():
|
||||||
|
deconstructed = str(resolved[source])
|
||||||
|
|
||||||
|
for item in mutation:
|
||||||
|
|
||||||
|
deconstructed = deconstructed.replace(str(item), "")
|
||||||
|
|
||||||
|
resolved[source] = deconstructed
|
||||||
|
|
||||||
|
return resolved
|
||||||
+51
-33
@@ -11,28 +11,7 @@ def buildSave(action, outputs):
|
|||||||
with open(f"{action.savepath}", "w") as save_file:
|
with open(f"{action.savepath}", "w") as save_file:
|
||||||
json.dump(save_data, save_file)
|
json.dump(save_data, save_file)
|
||||||
|
|
||||||
print(f"Data saved by {action.name} to {action.savepath}")
|
#print(f"Data saved by {action.name} to {action.savepath}")
|
||||||
|
|
||||||
database = sqlite3.connect("savedata/rmmanager.db")
|
|
||||||
for key, value in save_data.items():
|
|
||||||
database.execute("""
|
|
||||||
CREATE TABLE IF NOT EXISTS output_test (
|
|
||||||
dictionary TEXT PRIMARY KEY,
|
|
||||||
value TEXT NOT NULL
|
|
||||||
)
|
|
||||||
""")
|
|
||||||
|
|
||||||
database.execute("""
|
|
||||||
INSERT INTO output_test(dictionary, value)
|
|
||||||
VALUES (?, ?)
|
|
||||||
ON CONFLICT (dictionary)
|
|
||||||
DO UPDATE SET value = excluded.value
|
|
||||||
""", (key, value)
|
|
||||||
)
|
|
||||||
|
|
||||||
database.commit()
|
|
||||||
database.close()
|
|
||||||
|
|
||||||
return outputs
|
return outputs
|
||||||
|
|
||||||
def loadSave(action, outputs):
|
def loadSave(action, outputs):
|
||||||
@@ -43,11 +22,12 @@ def loadSave(action, outputs):
|
|||||||
for load_name in action.loaddata:
|
for load_name in action.loaddata:
|
||||||
outputs[load_name] = load_data[load_name]
|
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
|
return outputs
|
||||||
|
|
||||||
def saveRow(action, outputs, resolved):
|
def saveRow(action, outputs, resolved):
|
||||||
if hasattr(action, "saverow"):
|
if hasattr(action, "saverow"):
|
||||||
|
print("Saverow activated")
|
||||||
table = action.saverow["table"]
|
table = action.saverow["table"]
|
||||||
|
|
||||||
columns = action.saverow["columns"]
|
columns = action.saverow["columns"]
|
||||||
@@ -59,17 +39,23 @@ def saveRow(action, outputs, resolved):
|
|||||||
columnattr = ""
|
columnattr = ""
|
||||||
columnattr = key + " " + value
|
columnattr = key + " " + value
|
||||||
|
|
||||||
print(columnattr)
|
#print(columnattr)
|
||||||
column_creation.append(columnattr)
|
column_creation.append(columnattr)
|
||||||
|
|
||||||
rowitems = action.saverow["rowitems"]
|
rowitems = action.saverow["rowitems"]
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
for item in rowitems:
|
for item in rowitems:
|
||||||
if "outputs" in item:
|
try:
|
||||||
value = outputs[item["outputs"]]
|
if "outputs" in item:
|
||||||
elif "resolved" in item:
|
value = outputs[item["outputs"]]
|
||||||
value = resolved[item["resolved"]]
|
elif "resolved" in item:
|
||||||
|
value = resolved[item["resolved"]]
|
||||||
|
except KeyError as error:
|
||||||
|
print(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||||
|
print("Bypassing database save")
|
||||||
|
return False
|
||||||
|
|
||||||
values.append(value)
|
values.append(value)
|
||||||
|
|
||||||
@@ -86,14 +72,45 @@ def saveRow(action, outputs, resolved):
|
|||||||
column_names = ", ".join(column_list)
|
column_names = ", ".join(column_list)
|
||||||
placeholders = ", ".join(["?"] * len(values))
|
placeholders = ", ".join(["?"] * len(values))
|
||||||
|
|
||||||
database.execute(
|
query = f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})"
|
||||||
f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
|
||||||
tuple(values)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
if "onconflict" in action.saverow:
|
||||||
|
conflict = action.saverow["onconflict"]
|
||||||
|
|
||||||
|
target = conflict["target"]
|
||||||
|
columns = conflict["update"]
|
||||||
|
preserve_null = conflict.get("preservenull", False)
|
||||||
|
|
||||||
|
if columns:
|
||||||
|
if preserve_null:
|
||||||
|
assignments = ", ".join(
|
||||||
|
f"{column} = COALESCE(excluded.{column}, {table}.{column})"
|
||||||
|
for column in columns
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
assignments = ", ".join(
|
||||||
|
f"{column} = excluded.{column}"
|
||||||
|
for column in columns
|
||||||
|
)
|
||||||
|
|
||||||
|
query += f" ON CONFLICT({target}) DO UPDATE SET {assignments}"
|
||||||
|
else:
|
||||||
|
query += f" ON CONFLICT({target}) DO NOTHING"
|
||||||
|
|
||||||
|
database.execute(query, tuple(values))
|
||||||
database.commit()
|
database.commit()
|
||||||
database.close()
|
|
||||||
|
|
||||||
|
#database.execute(
|
||||||
|
# f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||||
|
# tuple(values)
|
||||||
|
#)
|
||||||
|
|
||||||
|
#database.commit()
|
||||||
|
#database.close()
|
||||||
|
|
||||||
|
print(f"Successfully saved data to {table} during {action.name}")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def readRow(action, resolved, outputs):
|
def readRow(action, resolved, outputs):
|
||||||
@@ -117,6 +134,7 @@ def readRow(action, resolved, outputs):
|
|||||||
searchcolumn = action.readrow["searchcolumn"]
|
searchcolumn = action.readrow["searchcolumn"]
|
||||||
|
|
||||||
values = []
|
values = []
|
||||||
|
|
||||||
for item in rowsearchvalue:
|
for item in rowsearchvalue:
|
||||||
if "outputs" in item:
|
if "outputs" in item:
|
||||||
value = outputs[item["outputs"]]
|
value = outputs[item["outputs"]]
|
||||||
|
|||||||
@@ -31,8 +31,12 @@ def buildSelect(action, outputs):
|
|||||||
#print(outputs[f"{action.alias}_select"])
|
#print(outputs[f"{action.alias}_select"])
|
||||||
|
|
||||||
return select_data, action, outputs
|
return select_data, action, outputs
|
||||||
except (KeyError, TypeError):
|
except KeyError as error:
|
||||||
print("Error in selection")
|
print(f"Error in selection of {error} during {action.name}")
|
||||||
|
|
||||||
|
except TypeError as error:
|
||||||
|
print(f"TypeError during select: {error} during {action.name}")
|
||||||
|
|
||||||
#select_data = ["no selection"]
|
#select_data = ["no selection"]
|
||||||
return select_data, action, outputs
|
return select_data, action, outputs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user