Passed
Push — master ( aeb165...d9ae97 )
by Dean
03:04
created

MessageType.title()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.6875
Metric Value
dl 0
loc 16
ccs 1
cts 4
cp 0.25
rs 9.4285
cc 2
crap 3.6875
1 1
from plugin.models.core import db
2
3 1
from playhouse.apsw_ext import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like playhouse.apsw_ext should generally be avoided.
Loading history...
4
5
6 1
class MessageCode(object):
7
    # Database (0x09)
8
    # - Schema (0x0901)
9 1
    DatabaseSchemaCorruptionReset = 0x90101
10
11
    # Release / Version (0x10)
12
    # - Upgrade (0x1001)
13 1
    UpgradePerformed = 0x100101
14
    # - Downgrade (0x1002)
15 1
    DowngradeUnclean = 0x100201
16
17
    # Network (0x11)
18
    # - Trakt (0x1101)
19 1
    TraktTimeout = 0x110101
20
21
    # TODO check for conflicting codes
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
22
23
24 1
class MessageType(object):
25 1
    __titles__  = None
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
__titles__ = None
^
Loading history...
26
27 1
    Generic     = 0x00
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Generic = 0x00
^
Loading history...
28 1
    Exception   = 0x01
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Exception = 0x01
^
Loading history...
29
30
    # Basic messages
31 1
    Info        = 0x02
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Info = 0x02
^
Loading history...
32 1
    Warning     = 0x04
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Warning = 0x04
^
Loading history...
33 1
    Error       = 0x08
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Error = 0x08
^
Loading history...
34 1
    Critical    = 0x16
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Critical = 0x16
^
Loading history...
35
36
    # Services
37 1
    Trakt       = 0x32
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Trakt = 0x32
^
Loading history...
38
39 1
    @classmethod
40
    def title(cls, value):
41
        if cls.__titles__ is None:
42
            cls.__titles__ = {
43
                MessageType.Generic:    None,
44
                MessageType.Exception:  "Exception",
45
46
                MessageType.Info:       "Info",
47
                MessageType.Warning:    "Warning",
48
                MessageType.Error:      "Error",
49
                MessageType.Critical:   "Critical",
50
51
                MessageType.Trakt:      "trakt.tv"
52
            }
53
54
        return cls.__titles__.get(value)
55
56
57 1
class Message(Model):
58 1
    Code = MessageCode
59 1
    Type = MessageType
60
61 1
    class Meta:
62 1
        database = db
63 1
        db_table = 'message'
64
65 1
    code = IntegerField(null=True)
66 1
    type = IntegerField()
67
68 1
    last_logged_at = DateTimeField()
69 1
    last_viewed_at = DateTimeField(null=True)
70
71
    # Tracking data
72 1
    exception_hash = CharField(null=True, unique=True, max_length=32)
73 1
    revision = IntegerField(null=True)
74
75 1
    version_base = CharField(max_length=12)
76 1
    version_branch = CharField(max_length=42)
77
78
    # User-friendly explanation
79 1
    summary = CharField(null=True, max_length=160)  # Short single-line summary
80 1
    description = TextField(null=True)  # Extra related details
81
82 1
    @property
83
    def viewed(self):
84
        if not self.last_viewed_at:
85
            return False
86
87
        return self.last_viewed_at > self.last_logged_at
88