diff options
author | XANTRONIX Development | 2021-12-10 15:10:30 -0500 |
---|---|---|
committer | XANTRONIX Development | 2021-12-10 15:10:30 -0500 |
commit | 688008fb961b7f9763139d6ac711272179a4e14b (patch) | |
tree | 33f31f1ceda316f7972c6855a476731dca2ed5ff | |
parent | b0995cdbe3f5ea282fdb3b3c01c69de9125e2ff2 (diff) | |
download | xas-688008fb961b7f9763139d6ac711272179a4e14b.tar.gz xas-688008fb961b7f9763139d6ac711272179a4e14b.tar.bz2 xas-688008fb961b7f9763139d6ac711272179a4e14b.zip |
[spiral emoji]
-rw-r--r-- | lib/xas/message.py | 22 | ||||
-rw-r--r-- | lib/xas/status.py | 25 |
2 files changed, 37 insertions, 10 deletions
diff --git a/lib/xas/message.py b/lib/xas/message.py new file mode 100644 index 0000000..dc673ef --- /dev/null +++ b/lib/xas/message.py @@ -0,0 +1,22 @@ +class Formatter(): + def __init__(self, id: int, db): + self.id = id + self.db = db + + def fmt(self, lookup, code, text=None): + status = lookup(code) + output = "%04d :: Code %03d :: %s" % (self.id, code, status.typeobj.name) + + if status.typeobj.name != status.description: + output += " :: " + status.description + + if text is not None: + output += " :: " + text + + return output + + def message(self, code, text=None): + return self.fmt(self.db.status, code, text) + + def error(self, code, text=None): + return self.fmt(self.db.error, code, text) diff --git a/lib/xas/status.py b/lib/xas/status.py index 720d93f..1465616 100644 --- a/lib/xas/status.py +++ b/lib/xas/status.py @@ -12,9 +12,9 @@ class ErrorType(StatusType): pass class Status(): - def __init__(self, id: int, typeof: StatusType, description: str): + def __init__(self, id: int, typeobj: StatusType, description: str): self.id = id - self.typeof = typeof + self.typeobj = typeobj self.description = description def __str__(self): @@ -39,18 +39,21 @@ class Database(): def load_types(self): targets = { - "xas_status_type": self.statusTypes, - "xas_error_type": self.errorTypes + "xas_status_type": (StatusType, self.statusTypes), + "xas_error_type": (ErrorType, self.errorTypes) } for table in targets.keys(): - target = targets[table] + typeof = targets[table][0] + target = targets[table][1] cr = self.db.cursor() cr.execute(f"select id, name from {table}") for row in cr.fetchall(): - target[row['id']] = row['name'] + typeobj = typeof(row['id'], row['name']) + + target[typeobj.id] = typeobj def status_type(self, id: int): return self.statusTypes[id] @@ -60,19 +63,21 @@ class Database(): def load_statuses(self): targets = { - "xas_status": (Status, self.statuses), - "xas_error": (Error, self.errors) + "xas_status": (Status, self.statusTypes, self.statuses), + "xas_error": (Error, self.errorTypes, self.errors) } for table in targets.keys(): typeof = targets[table][0] - target = targets[table][1] + types = targets[table][1] + target = targets[table][2] 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']) + typeobj = types[row['type_id']] + obj = typeof(row['id'], types[row['type_id']], row['description']) target[obj.id] = obj |