-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
service.py
80 lines (53 loc) · 2.14 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
#################################################################################################
import threading
import xbmc
from jellyfin_kodi.entrypoint.service import Service
from jellyfin_kodi.helper.utils import settings
from jellyfin_kodi.helper import LazyLogger
#################################################################################################
LOG = LazyLogger(__name__)
DELAY = int(settings("startupDelay") if settings("SyncInstallRunDone.bool") else 4)
#################################################################################################
class ServiceManager(threading.Thread):
"""Service thread.
To allow to restart and reload modules internally.
"""
exception = None
def __init__(self):
threading.Thread.__init__(self)
def run(self):
service = None
try:
service = Service()
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
raise Exception("Aborted during startup delay")
service.service()
except Exception as error:
LOG.exception(error)
if service is not None:
# TODO: fix this properly as to not match on str()
if "ExitService" not in str(error):
service.shutdown()
if "RestartService" in str(error):
service.reload_objects()
self.exception = error
if __name__ == "__main__":
LOG.info("-->[ service ]")
LOG.info("Delay startup by %s seconds.", DELAY)
while True:
if not settings("enableAddon.bool"):
LOG.warning("Jellyfin for Kodi is not enabled.")
break
try:
session = ServiceManager()
session.start()
session.join() # Block until the thread exits.
if "RestartService" in str(session.exception):
continue
except Exception as error:
"""Issue initializing the service."""
LOG.exception(error)
break
LOG.info("--<[ service ]")