summaryrefslogtreecommitdiffstats
path: root/py/xas/message.py
blob: e297e408c5b4630ef352171ecb7dd1a126ddd5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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" % (self.id, code)

        if status.typeobj.name == status.description:
            output += " :: " + status.typeobj.name
        else:
            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)