|
1
|
1 |
|
from plugin.core.environment import translate as _ |
|
2
|
1 |
|
from plugin.models.core import db |
|
3
|
|
|
|
|
4
|
1 |
|
from exception_wrappers.libraries.playhouse.apsw_ext import * |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
1 |
|
class MessageCode(object): |
|
8
|
|
|
# Database (0x09) |
|
9
|
|
|
# - Schema (0x0901) |
|
10
|
1 |
|
DatabaseSchemaCorruptionReset = 0x90101 |
|
11
|
|
|
|
|
12
|
|
|
# Release / Version (0x10) |
|
13
|
|
|
# - Upgrade (0x1001) |
|
14
|
1 |
|
UpgradePerformed = 0x100101 |
|
15
|
|
|
# - Downgrade (0x1002) |
|
16
|
1 |
|
DowngradeUnclean = 0x100201 |
|
17
|
|
|
|
|
18
|
|
|
# Network (0x11) |
|
19
|
|
|
# - Trakt (0x1101) |
|
20
|
1 |
|
TraktTimeout = 0x110101 |
|
21
|
|
|
|
|
22
|
|
|
# TODO check for conflicting codes |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
1 |
|
class MessageType(object): |
|
26
|
1 |
|
__titles__ = None |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
1 |
|
Generic = 0x00 |
|
|
|
|
|
|
29
|
1 |
|
Exception = 0x01 |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
# Basic messages |
|
32
|
1 |
|
Info = 0x02 |
|
|
|
|
|
|
33
|
1 |
|
Warning = 0x04 |
|
|
|
|
|
|
34
|
1 |
|
Error = 0x08 |
|
|
|
|
|
|
35
|
1 |
|
Critical = 0x16 |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
# Services |
|
38
|
1 |
|
Trakt = 0x32 |
|
|
|
|
|
|
39
|
1 |
|
Plex = 0x64 |
|
|
|
|
|
|
40
|
1 |
|
Sentry = 0x128 |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
1 |
|
@classmethod |
|
43
|
|
|
def title(cls, value): |
|
44
|
|
|
if cls.__titles__ is None: |
|
45
|
|
|
cls.__titles__ = { |
|
46
|
|
|
MessageType.Generic: None, |
|
47
|
|
|
MessageType.Exception: _("Exception"), |
|
48
|
|
|
|
|
49
|
|
|
MessageType.Info: _("Info"), |
|
50
|
|
|
MessageType.Warning: _("Warning"), |
|
51
|
|
|
MessageType.Error: _("Error"), |
|
52
|
|
|
MessageType.Critical: _("Critical"), |
|
53
|
|
|
|
|
54
|
|
|
MessageType.Trakt: _("Trakt.tv"), |
|
55
|
|
|
MessageType.Plex: _("Plex.tv"), |
|
56
|
|
|
MessageType.Sentry: _("Sentry") |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return cls.__titles__.get(value) |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
1 |
|
class Message(Model): |
|
63
|
1 |
|
Code = MessageCode |
|
64
|
1 |
|
Type = MessageType |
|
65
|
|
|
|
|
66
|
1 |
|
class Meta: |
|
67
|
1 |
|
database = db |
|
68
|
1 |
|
db_table = 'message' |
|
69
|
|
|
|
|
70
|
1 |
|
indexes = ( |
|
71
|
|
|
(('type', 'exception_hash'), True), |
|
72
|
|
|
) |
|
73
|
|
|
|
|
74
|
1 |
|
code = IntegerField(null=True) |
|
75
|
1 |
|
type = IntegerField() |
|
76
|
|
|
|
|
77
|
1 |
|
last_logged_at = DateTimeField() |
|
78
|
1 |
|
last_viewed_at = DateTimeField(null=True) |
|
79
|
|
|
|
|
80
|
|
|
# Tracking data |
|
81
|
1 |
|
exception_hash = CharField(null=True, max_length=32) |
|
82
|
1 |
|
revision = IntegerField(null=True) |
|
83
|
|
|
|
|
84
|
1 |
|
version_base = CharField(max_length=12) |
|
85
|
1 |
|
version_branch = CharField(max_length=42) |
|
86
|
|
|
|
|
87
|
|
|
# User-friendly explanation |
|
88
|
1 |
|
summary = CharField(null=True, max_length=160) # Short single-line summary |
|
89
|
1 |
|
description = TextField(null=True) # Extra related details |
|
90
|
|
|
|
|
91
|
1 |
|
@property |
|
92
|
|
|
def viewed(self): |
|
93
|
|
|
if not self.last_viewed_at: |
|
94
|
|
|
return False |
|
95
|
|
|
|
|
96
|
|
|
return self.last_viewed_at > self.last_logged_at |
|
97
|
|
|
|