1
|
1 |
|
from plugin.models.core import db |
2
|
|
|
|
3
|
1 |
|
from playhouse.apsw_ext import * |
|
|
|
|
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 |
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
1 |
|
class MessageType(object): |
25
|
1 |
|
__titles__ = None |
|
|
|
|
26
|
|
|
|
27
|
1 |
|
Generic = 0x00 |
|
|
|
|
28
|
1 |
|
Exception = 0x01 |
|
|
|
|
29
|
|
|
|
30
|
|
|
# Basic messages |
31
|
1 |
|
Info = 0x02 |
|
|
|
|
32
|
1 |
|
Warning = 0x04 |
|
|
|
|
33
|
1 |
|
Error = 0x08 |
|
|
|
|
34
|
1 |
|
Critical = 0x16 |
|
|
|
|
35
|
|
|
|
36
|
|
|
# Services |
37
|
1 |
|
Trakt = 0x32 |
|
|
|
|
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
|
|
|
|