summaryrefslogtreecommitdiffstats
path: root/lib/xas/status.py
diff options
context:
space:
mode:
authorXANTRONIX Development2021-12-10 13:31:58 -0500
committerXANTRONIX Development2021-12-10 13:31:58 -0500
commitb0995cdbe3f5ea282fdb3b3c01c69de9125e2ff2 (patch)
treee7a5032f08abf3dbab333b9ccbf087ec86bfdd46 /lib/xas/status.py
parentb9c293ada9d46caa167a88d3b322f94cccf4fad8 (diff)
downloadxas-b0995cdbe3f5ea282fdb3b3c01c69de9125e2ff2.tar.gz
xas-b0995cdbe3f5ea282fdb3b3c01c69de9125e2ff2.tar.bz2
xas-b0995cdbe3f5ea282fdb3b3c01c69de9125e2ff2.zip
initial commit of lib/xas/status.py
Diffstat (limited to 'lib/xas/status.py')
-rw-r--r--lib/xas/status.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/xas/status.py b/lib/xas/status.py
new file mode 100644
index 0000000..720d93f
--- /dev/null
+++ b/lib/xas/status.py
@@ -0,0 +1,83 @@
+import sqlite3
+
+class StatusType():
+ def __init__(self, id, name):
+ self.id = id
+ self.name = name
+
+ def __str__(self):
+ return self.name
+
+class ErrorType(StatusType):
+ pass
+
+class Status():
+ def __init__(self, id: int, typeof: StatusType, description: str):
+ self.id = id
+ self.typeof = typeof
+ self.description = description
+
+ def __str__(self):
+ return self.description
+
+class Error(Status):
+ pass
+
+class Database():
+ def __init__(self, filename: str):
+ self.db = sqlite3.connect(filename)
+ self.db.row_factory = sqlite3.Row
+
+ self.statusTypes = dict()
+ self.statuses = dict()
+
+ self.errorTypes = dict()
+ self.errors = dict()
+
+ self.load_types()
+ self.load_statuses()
+
+ def load_types(self):
+ targets = {
+ "xas_status_type": self.statusTypes,
+ "xas_error_type": self.errorTypes
+ }
+
+ for table in targets.keys():
+ target = targets[table]
+
+ cr = self.db.cursor()
+ cr.execute(f"select id, name from {table}")
+
+ for row in cr.fetchall():
+ target[row['id']] = row['name']
+
+ def status_type(self, id: int):
+ return self.statusTypes[id]
+
+ def error_type(self, id: int):
+ return self.errorTypes[id]
+
+ def load_statuses(self):
+ targets = {
+ "xas_status": (Status, self.statuses),
+ "xas_error": (Error, self.errors)
+ }
+
+ for table in targets.keys():
+ typeof = targets[table][0]
+ target = targets[table][1]
+
+ cr = self.db.cursor()
+ cr.execute(f"select id, type_id, description from {table}")
+
+ for row in cr.fetchall():
+ obj = typeof(row['id'], row['type_id'], row['description'])
+
+ target[obj.id] = obj
+
+ def status(self, id):
+ return self.statuses[id]
+
+ def error(self, id):
+ return self.errors[id]