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"):
|
||||
for label, keys in action.resolve["get"].items():
|
||||
target = item
|
||||
try:
|
||||
for key in keys:
|
||||
target = target[key]
|
||||
|
||||
for key in keys:
|
||||
target = target.get(key)
|
||||
#target = target[key]
|
||||
except (KeyError, IndexError) as error:
|
||||
print(f"Resolver target key/index {error} not found during {action.name}")
|
||||
target = None
|
||||
|
||||
resolved[label] = target
|
||||
|
||||
if "construct" in action.resolve:
|
||||
for label2, piece in action.resolve["construct"].items():
|
||||
constructed = ""
|
||||
@@ -21,6 +25,7 @@ def resolveItem(action, item):
|
||||
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():
|
||||
@@ -80,4 +85,56 @@ def resolveItem2(action, item):
|
||||
|
||||
resolved[source] = deconstructed
|
||||
|
||||
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
|
||||
+54
-36
@@ -11,28 +11,7 @@ def buildSave(action, outputs):
|
||||
with open(f"{action.savepath}", "w") as save_file:
|
||||
json.dump(save_data, save_file)
|
||||
|
||||
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()
|
||||
|
||||
#print(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def loadSave(action, outputs):
|
||||
@@ -43,11 +22,12 @@ def loadSave(action, outputs):
|
||||
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
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
if hasattr(action, "saverow"):
|
||||
print("Saverow activated")
|
||||
table = action.saverow["table"]
|
||||
|
||||
columns = action.saverow["columns"]
|
||||
@@ -59,18 +39,24 @@ def saveRow(action, outputs, resolved):
|
||||
columnattr = ""
|
||||
columnattr = key + " " + value
|
||||
|
||||
print(columnattr)
|
||||
#print(columnattr)
|
||||
column_creation.append(columnattr)
|
||||
|
||||
rowitems = action.saverow["rowitems"]
|
||||
|
||||
values = []
|
||||
for item in rowitems:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
for item in rowitems:
|
||||
try:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
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)
|
||||
|
||||
database = sqlite3.connect("savedata/rmmanager.db")
|
||||
@@ -86,14 +72,45 @@ def saveRow(action, outputs, resolved):
|
||||
column_names = ", ".join(column_list)
|
||||
placeholders = ", ".join(["?"] * len(values))
|
||||
|
||||
database.execute(
|
||||
f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})",
|
||||
tuple(values)
|
||||
)
|
||||
query = f"INSERT INTO {table} ({column_names}) VALUES ({placeholders})"
|
||||
|
||||
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.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):
|
||||
@@ -117,12 +134,13 @@ def readRow(action, resolved, outputs):
|
||||
searchcolumn = action.readrow["searchcolumn"]
|
||||
|
||||
values = []
|
||||
|
||||
for item in rowsearchvalue:
|
||||
if "outputs" in item:
|
||||
value = outputs[item["outputs"]]
|
||||
elif "resolved" in item:
|
||||
value = resolved[item["resolved"]]
|
||||
|
||||
|
||||
values.append(value)
|
||||
|
||||
exports = action.readrow["export"]
|
||||
|
||||
@@ -31,8 +31,12 @@ def buildSelect(action, outputs):
|
||||
#print(outputs[f"{action.alias}_select"])
|
||||
|
||||
return select_data, action, outputs
|
||||
except (KeyError, TypeError):
|
||||
print("Error in selection")
|
||||
except KeyError as error:
|
||||
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"]
|
||||
return select_data, action, outputs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user