Merge conflicts service.py

This commit is contained in:
tomkat83 2016-08-29 19:27:05 +02:00
parent b97907b459
commit afda9d0b1a

View file

@ -2,6 +2,7 @@
############################################################################### ###############################################################################
import logging
import os import os
import sys import sys
import Queue import Queue
@ -14,25 +15,24 @@ import xbmcgui
_addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect') _addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
try: try:
addon_path = _addon.getAddonInfo('path').decode('utf-8') _addon_path = _addon.getAddonInfo('path').decode('utf-8')
except TypeError: except TypeError:
addon_path = _addon.getAddonInfo('path').decode() _addon_path = _addon.getAddonInfo('path').decode()
try: try:
base_resource = xbmc.translatePath(os.path.join( _base_resource = xbmc.translatePath(os.path.join(
addon_path, _addon_path,
'resources', 'resources',
'lib')).decode('utf-8') 'lib')).decode('utf-8')
except TypeError: except TypeError:
base_resource = xbmc.translatePath(os.path.join( _base_resource = xbmc.translatePath(os.path.join(
addon_path, _addon_path,
'resources', 'resources',
'lib')).decode() 'lib')).decode()
sys.path.append(_base_resource)
sys.path.append(base_resource)
############################################################################### ###############################################################################
import utils from utils import settings, window, language as lang
import userclient import userclient
import clientinfo import clientinfo
import initialsetup import initialsetup
@ -47,8 +47,14 @@ import PlexCompanion
############################################################################### ###############################################################################
import loghandler
loghandler.config()
log = logging.getLogger("PLEX.default")
###############################################################################
@utils.logging
class Service(): class Service():
welcome_msg = True welcome_msg = True
@ -63,24 +69,23 @@ class Service():
def __init__(self): def __init__(self):
log = self.logMsg
window = utils.window
self.clientInfo = clientinfo.ClientInfo() self.clientInfo = clientinfo.ClientInfo()
logLevel = self.getLogLevel() logLevel = self.getLogLevel()
self.monitor = xbmc.Monitor() self.monitor = xbmc.Monitor()
window('plex_logLevel', value=str(logLevel)) window('plex_logLevel', value=str(logLevel))
window('plex_kodiProfile', value=xbmc.translatePath("special://profile")) window('plex_kodiProfile',
window('plex_pluginpath', value=utils.settings('useDirectPaths')) value=xbmc.translatePath("special://profile"))
# Initial logging # Initial logging
log("======== START %s ========" % self.addonName, 0) log.warn("======== START %s ========" % self.addonName)
log("Platform: %s" % (self.clientInfo.getPlatform()), 0) log.warn("Platform: %s" % (self.clientInfo.getPlatform()))
log("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'), 0) log.warn("KODI Version: %s" % xbmc.getInfoLabel('System.BuildVersion'))
log("%s Version: %s" % (self.addonName, self.clientInfo.getVersion()), 0) log.warn("%s Version: %s" % (self.addonName,
log("Using plugin paths: %s" % (utils.settings('useDirectPaths') != "true"), 0) self.clientInfo.getVersion()))
log("Log Level: %s" % logLevel, 0) log.warn("Using plugin paths: %s"
% (settings('useDirectPaths') != "true"))
log.warn("Log Level: %s" % logLevel)
# Reset window props for profile switch # Reset window props for profile switch
properties = [ properties = [
@ -109,17 +114,12 @@ class Service():
def getLogLevel(self): def getLogLevel(self):
try: try:
logLevel = int(utils.settings('logLevel')) logLevel = int(settings('logLevel'))
except ValueError: except ValueError:
logLevel = 0 logLevel = 0
return logLevel return logLevel
def ServiceEntryPoint(self): def ServiceEntryPoint(self):
log = self.logMsg
window = utils.window
lang = utils.language
# Important: Threads depending on abortRequest will not trigger # Important: Threads depending on abortRequest will not trigger
# if profile switch happens more than once. # if profile switch happens more than once.
monitor = self.monitor monitor = self.monitor
@ -131,7 +131,7 @@ class Service():
# Queue for background sync # Queue for background sync
queue = Queue.Queue(maxsize=200) queue = Queue.Queue(maxsize=200)
connectMsg = True if utils.settings('connectMsg') == 'true' else False connectMsg = True if settings('connectMsg') == 'true' else False
# Initialize important threads # Initialize important threads
user = userclient.UserClient() user = userclient.UserClient()
@ -144,9 +144,9 @@ class Service():
if window('plex_kodiProfile') != kodiProfile: if window('plex_kodiProfile') != kodiProfile:
# Profile change happened, terminate this thread and others # Profile change happened, terminate this thread and others
log("Kodi profile was: %s and changed to: %s. Terminating old " log.warn("Kodi profile was: %s and changed to: %s. "
"PlexKodiConnect thread." "Terminating old PlexKodiConnect thread."
% (kodiProfile, utils.window('plex_kodiProfile')), 1) % (kodiProfile, window('plex_kodiProfile')))
break break
# Before proceeding, need to make sure: # Before proceeding, need to make sure:
@ -190,7 +190,7 @@ class Service():
if (user.currUser is None) and self.warn_auth: if (user.currUser is None) and self.warn_auth:
# Alert user is not authenticated and suppress future warning # Alert user is not authenticated and suppress future warning
self.warn_auth = False self.warn_auth = False
log("Not authenticated yet.", 1) log.warn("Not authenticated yet.")
# User access is restricted. # User access is restricted.
# Keep verifying until access is granted # Keep verifying until access is granted
@ -219,7 +219,7 @@ class Service():
# Server is offline or cannot be reached # Server is offline or cannot be reached
# Alert the user and suppress future warning # Alert the user and suppress future warning
if self.server_online: if self.server_online:
log("Server is offline.", -1) log.error("Server is offline.")
window('plex_online', value="false") window('plex_online', value="false")
# Suspend threads # Suspend threads
window('suspend_LibraryThread', value='true') window('suspend_LibraryThread', value='true')
@ -257,7 +257,7 @@ class Service():
time=5000, time=5000,
sound=False) sound=False)
self.server_online = True self.server_online = True
log("Server %s is online and ready." % server, 1) log.warn("Server %s is online and ready." % server)
window('plex_online', value="true") window('plex_online', value="true")
if window('plex_authenticated') == 'true': if window('plex_authenticated') == 'true':
# Server got offline when we were authenticated. # Server got offline when we were authenticated.
@ -282,41 +282,41 @@ class Service():
# Terminating PlexKodiConnect # Terminating PlexKodiConnect
# Tell all threads to terminate (e.g. several lib sync threads) # Tell all threads to terminate (e.g. several lib sync threads)
utils.window('plex_terminateNow', value='true') window('plex_terminateNow', value='true')
try: try:
plexCompanion.stopThread() plexCompanion.stopThread()
except: except:
xbmc.log('plexCompanion already shut down') log.warn('plexCompanion already shut down')
try: try:
library.stopThread() library.stopThread()
except: except:
xbmc.log('Library sync already shut down') log.warn('Library sync already shut down')
try: try:
ws.stopThread() ws.stopThread()
except: except:
xbmc.log('Websocket client already shut down') log.warn('Websocket client already shut down')
try: try:
user.stopThread() user.stopThread()
except: except:
xbmc.log('User client already shut down') log.warn('User client already shut down')
try: try:
downloadutils.DownloadUtils().stopSession() downloadutils.DownloadUtils().stopSession()
except: except:
pass pass
log("======== STOP %s ========" % self.addonName, 0) log.warn("======== STOP %s ========" % self.addonName)
# Delay option # Delay option
delay = int(utils.settings('startupDelay')) delay = int(settings('startupDelay'))
xbmc.log("Delaying Plex startup by: %s sec..." % delay) log.warn("Delaying Plex startup by: %s sec..." % delay)
if delay and xbmc.Monitor().waitForAbort(delay): if delay and xbmc.Monitor().waitForAbort(delay):
# Start the service # Start the service
xbmc.log("Abort requested while waiting. PKC not started.") log.warn("Abort requested while waiting. PKC not started.")
else: else:
Service().ServiceEntryPoint() Service().ServiceEntryPoint()