Housekeeping and migrated prints to logging
This commit is contained in:
@@ -21,54 +21,43 @@ def applyConditions(definition, dictionary, outputs):
|
||||
|
||||
if filter["operator"] == ">=":
|
||||
if int(resolvedvalue or 0) >= int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "<=":
|
||||
if int(resolvedvalue or 0) <= int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "==":
|
||||
if resolvedvalue == filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "!=":
|
||||
if resolvedvalue != filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == ">":
|
||||
if int(resolvedvalue or 0) > int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "<":
|
||||
if int(resolvedvalue or 0) < int(filtervalue):
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "in":
|
||||
if filtervalue in dictionary:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "is":
|
||||
if resolvedvalue is filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
if filter["operator"] == "is not":
|
||||
if resolvedvalue is not filtervalue:
|
||||
print(filter["print"])
|
||||
return True, filter
|
||||
|
||||
except KeyError:
|
||||
print(f"Value not present in runtime for filtering during {definition.name}")
|
||||
#print(filter)
|
||||
return True, filter
|
||||
#continue
|
||||
|
||||
#except TypeError:
|
||||
# print("TypeError")
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
from core.runtime.applyconditions import applyConditions
|
||||
|
||||
def buildFirewall(listener, outputs):
|
||||
firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true"
|
||||
#firewall_log = os.environ.get("LOGS_FIREWALL", "false").lower() == "true"
|
||||
firewall_log = True
|
||||
|
||||
status_code = 200
|
||||
outputs["firewall_allowed"] = []
|
||||
@@ -13,20 +15,24 @@ def buildFirewall(listener, outputs):
|
||||
|
||||
if match:
|
||||
status_code = filter.get("status_code", 200)
|
||||
if firewall_log:
|
||||
logging.info(filter.get("print"))
|
||||
logging.info(f"Returning status_code: {status_code}")
|
||||
continue
|
||||
|
||||
#This needs to be moved into definitions but until logic is put in place it lives here.
|
||||
if "com.loxthelion.rmass_message_id" in item.get("content", {}):
|
||||
status_code = 200
|
||||
print("Excluding previously imported items")
|
||||
print(f"Returning status_code: {status_code}")
|
||||
if firewall_log:
|
||||
logging.info("Excluding previously imported items")
|
||||
logging.info(f"Returning status_code: {status_code}")
|
||||
|
||||
continue
|
||||
|
||||
outputs["firewall_allowed"].append(item)
|
||||
|
||||
if outputs["firewall_allowed"]:
|
||||
return True, outputs, status_code
|
||||
if outputs["firewall_allowed"] != []:
|
||||
return True, status_code
|
||||
|
||||
#Needs to be present to prevent TypeError
|
||||
return False, outputs, status_code
|
||||
return False, status_code
|
||||
+13
-14
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import logging
|
||||
|
||||
def buildSave(action, outputs):
|
||||
savedata_log = os.environ.get("LOGS_SAVE_DATA_ACCESS", "false").lower() == "true"
|
||||
@@ -39,7 +40,7 @@ def buildSave(action, outputs):
|
||||
pass
|
||||
|
||||
if savedata_log:
|
||||
print(f"Data saved by {action.name} to {action.savepath}")
|
||||
logging.info(f"Data saved by {action.name} to {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def loadSave(action, outputs):
|
||||
@@ -53,7 +54,7 @@ def loadSave(action, outputs):
|
||||
outputs[load_name] = load_data[load_name]
|
||||
|
||||
if savedata_log:
|
||||
print(f"Data loaded by {action.name} from {action.savepath}")
|
||||
logging.info(f"Data loaded by {action.name} from {action.savepath}")
|
||||
return outputs
|
||||
|
||||
def saveRow(action, outputs, resolved):
|
||||
@@ -87,8 +88,8 @@ def saveRow(action, outputs, 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")
|
||||
logging.error(f"The save data for {error} was not located in its respective dictionary during {action.name}")
|
||||
logging.error("Bypassing database save")
|
||||
return False
|
||||
|
||||
values.append(value)
|
||||
@@ -137,7 +138,7 @@ def saveRow(action, outputs, resolved):
|
||||
database.execute(query, tuple(values))
|
||||
|
||||
except sqlite3.IntegrityError as error:
|
||||
print(f"Unable to complete database write during {action.name}: {error}")
|
||||
logging.error(f"Unable to complete database write during {action.name}: {error}")
|
||||
return False
|
||||
|
||||
#database.execute(
|
||||
@@ -148,7 +149,7 @@ def saveRow(action, outputs, resolved):
|
||||
#database.commit()
|
||||
#database.close()
|
||||
|
||||
print(f"Successfully saved data to {table} during {action.name}")
|
||||
logging.info(f"Successfully saved data to {table} during {action.name}")
|
||||
|
||||
return True
|
||||
|
||||
@@ -206,8 +207,8 @@ def readRow(action, resolved, outputs):
|
||||
""",
|
||||
(value,)
|
||||
)
|
||||
#print("DEBUG READROW TARGET ITEM")
|
||||
#print(value)
|
||||
logging.debug("DEBUG READROW TARGET ITEM")
|
||||
logging.debug(value)
|
||||
|
||||
result = cursor.fetchone()
|
||||
|
||||
@@ -216,15 +217,13 @@ def readRow(action, resolved, outputs):
|
||||
for column_index, output_name in exports.items():
|
||||
dbtarget = result[column_index]
|
||||
outputs[output_name] = dbtarget# result[column_index]
|
||||
#print("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
||||
#print(outputs[output_name])
|
||||
#print(dbtarget)
|
||||
logging.debug("DEBUGGING DATABASE LINE EXTRACTION IN READROW")
|
||||
logging.debug(outputs[output_name])
|
||||
logging.debug(dbtarget)
|
||||
|
||||
return resolved, outputs
|
||||
else:
|
||||
print(f"Search target {value} not found in database table {table}")
|
||||
logging.info(f"Search target {value} not found in database table {table}")
|
||||
return resolved, outputs
|
||||
|
||||
#print("READROW SEARCH RESULT")
|
||||
#print(target)
|
||||
return resolved, outputs
|
||||
Reference in New Issue
Block a user