Prettify
This commit is contained in:
parent
bd85bb445e
commit
a2193ab01f
1 changed files with 40 additions and 40 deletions
|
@ -5,7 +5,7 @@ from logging import getLogger
|
|||
import xml.etree.ElementTree as etree
|
||||
import requests
|
||||
|
||||
from utils import settings, window, language as lang, dialog
|
||||
from utils import window, language as lang, dialog
|
||||
import clientinfo as client
|
||||
|
||||
import state
|
||||
|
@ -16,7 +16,7 @@ import state
|
|||
import requests.packages.urllib3
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
|
||||
log = getLogger("PLEX."+__name__)
|
||||
LOG = getLogger("PLEX." + __name__)
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
@ -46,7 +46,7 @@ class DownloadUtils():
|
|||
Reserved for userclient only
|
||||
"""
|
||||
self.server = server
|
||||
log.debug("Set server: %s" % server)
|
||||
LOG.debug("Set server: %s", server)
|
||||
|
||||
def setToken(self, token):
|
||||
"""
|
||||
|
@ -54,9 +54,9 @@ class DownloadUtils():
|
|||
"""
|
||||
self.token = token
|
||||
if token == '':
|
||||
log.debug('Set token: empty token!')
|
||||
LOG.debug('Set token: empty token!')
|
||||
else:
|
||||
log.debug("Set token: xxxxxxx")
|
||||
LOG.debug("Set token: xxxxxxx")
|
||||
|
||||
def setSSL(self, verifySSL=None, certificate=None):
|
||||
"""
|
||||
|
@ -74,8 +74,8 @@ class DownloadUtils():
|
|||
self.s.verify = verifySSL
|
||||
if certificate:
|
||||
self.s.cert = certificate
|
||||
log.debug("Verify SSL certificates set to: %s", verifySSL)
|
||||
log.debug("SSL client side certificate set to: %s", certificate)
|
||||
LOG.debug("Verify SSL certificates set to: %s", verifySSL)
|
||||
LOG.debug("SSL client side certificate set to: %s", certificate)
|
||||
|
||||
def startSession(self, reset=False):
|
||||
"""
|
||||
|
@ -107,18 +107,18 @@ class DownloadUtils():
|
|||
self.s.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||
self.s.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
|
||||
|
||||
log.info("Requests session started on: %s" % self.server)
|
||||
LOG.info("Requests session started on: %s", self.server)
|
||||
|
||||
def stopSession(self):
|
||||
try:
|
||||
self.s.close()
|
||||
except:
|
||||
log.info("Requests session already closed")
|
||||
LOG.info("Requests session already closed")
|
||||
try:
|
||||
del self.s
|
||||
except:
|
||||
pass
|
||||
log.info('Request session stopped')
|
||||
LOG.info('Request session stopped')
|
||||
|
||||
def getHeader(self, options=None):
|
||||
header = client.getXArgsDeviceInfo()
|
||||
|
@ -164,7 +164,7 @@ class DownloadUtils():
|
|||
try:
|
||||
s = self.s
|
||||
except AttributeError:
|
||||
log.info("Request session does not exist: start one")
|
||||
LOG.info("Request session does not exist: start one")
|
||||
self.startSession()
|
||||
s = self.s
|
||||
# Replace for the real values
|
||||
|
@ -201,38 +201,38 @@ class DownloadUtils():
|
|||
|
||||
# THE EXCEPTIONS
|
||||
except requests.exceptions.SSLError as e:
|
||||
log.warn("Invalid SSL certificate for: %s" % url)
|
||||
log.warn(e)
|
||||
LOG.warn("Invalid SSL certificate for: %s", url)
|
||||
LOG.warn(e)
|
||||
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
# Connection error
|
||||
log.warn("Server unreachable at: %s" % url)
|
||||
log.warn(e)
|
||||
LOG.warn("Server unreachable at: %s", url)
|
||||
LOG.warn(e)
|
||||
|
||||
except requests.exceptions.Timeout as e:
|
||||
log.warn("Server timeout at: %s" % url)
|
||||
log.warn(e)
|
||||
LOG.warn("Server timeout at: %s", url)
|
||||
LOG.warn(e)
|
||||
|
||||
except requests.exceptions.HTTPError as e:
|
||||
log.warn('HTTP Error at %s' % url)
|
||||
log.warn(e)
|
||||
LOG.warn('HTTP Error at %s', url)
|
||||
LOG.warn(e)
|
||||
|
||||
except requests.exceptions.TooManyRedirects as e:
|
||||
log.warn("Too many redirects connecting to: %s" % url)
|
||||
log.warn(e)
|
||||
LOG.warn("Too many redirects connecting to: %s", url)
|
||||
LOG.warn(e)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
log.warn("Unknown error connecting to: %s" % url)
|
||||
log.warn(e)
|
||||
LOG.warn("Unknown error connecting to: %s", url)
|
||||
LOG.warn(e)
|
||||
|
||||
except SystemExit:
|
||||
log.info('SystemExit detected, aborting download')
|
||||
LOG.info('SystemExit detected, aborting download')
|
||||
self.stopSession()
|
||||
|
||||
except:
|
||||
log.warn('Unknown error while downloading. Traceback:')
|
||||
LOG.warn('Unknown error while downloading. Traceback:')
|
||||
import traceback
|
||||
log.warn(traceback.format_exc())
|
||||
LOG.warn(traceback.format_exc())
|
||||
|
||||
# THE RESPONSE #####
|
||||
else:
|
||||
|
@ -254,19 +254,19 @@ class DownloadUtils():
|
|||
# Called when checking a connect - no need for rash action
|
||||
return 401
|
||||
r.encoding = 'utf-8'
|
||||
log.warn('HTTP error 401 from PMS %s' % url)
|
||||
log.info(r.text)
|
||||
LOG.warn('HTTP error 401 from PMS %s', url)
|
||||
LOG.info(r.text)
|
||||
if '401 Unauthorized' in r.text:
|
||||
# Truly unauthorized
|
||||
window('countUnauthorized',
|
||||
value=str(int(window('countUnauthorized')) + 1))
|
||||
if (int(window('countUnauthorized')) >=
|
||||
self.unauthorizedAttempts):
|
||||
log.warn('We seem to be truly unauthorized for PMS'
|
||||
' %s ' % url)
|
||||
LOG.warn('We seem to be truly unauthorized for PMS'
|
||||
' %s ', url)
|
||||
if state.PMS_STATUS not in ('401', 'Auth'):
|
||||
# Tell userclient token has been revoked.
|
||||
log.debug('Setting PMS server status to '
|
||||
LOG.debug('Setting PMS server status to '
|
||||
'unauthorized')
|
||||
state.PMS_STATUS = '401'
|
||||
window('plex_serverStatus', value="401")
|
||||
|
@ -276,7 +276,7 @@ class DownloadUtils():
|
|||
icon='{error}')
|
||||
else:
|
||||
# there might be other 401 where e.g. PMS under strain
|
||||
log.info('PMS might only be under strain')
|
||||
LOG.info('PMS might only be under strain')
|
||||
return 401
|
||||
|
||||
elif r.status_code in (200, 201):
|
||||
|
@ -304,18 +304,18 @@ class DownloadUtils():
|
|||
# update
|
||||
pass
|
||||
else:
|
||||
log.warn("Unable to convert the response for: "
|
||||
"%s" % url)
|
||||
log.warn("Received headers were: %s" % r.headers)
|
||||
log.warn('Received text: %s', r.text)
|
||||
LOG.warn("Unable to convert the response for: "
|
||||
"%s", url)
|
||||
LOG.warn("Received headers were: %s", r.headers)
|
||||
LOG.warn('Received text: %s', r.text)
|
||||
return True
|
||||
elif r.status_code == 403:
|
||||
# E.g. deleting a PMS item
|
||||
log.warn('PMS sent 403: Forbidden error for url %s' % url)
|
||||
LOG.warn('PMS sent 403: Forbidden error for url %s', url)
|
||||
return None
|
||||
else:
|
||||
r.encoding = 'utf-8'
|
||||
log.warn('Unknown answer from PMS %s with status code %s. ',
|
||||
LOG.warn('Unknown answer from PMS %s with status code %s. ',
|
||||
url, r.status_code)
|
||||
return True
|
||||
|
||||
|
@ -326,8 +326,8 @@ class DownloadUtils():
|
|||
window('countError',
|
||||
value=str(int(window('countError')) + 1))
|
||||
if int(window('countError')) >= self.connectionAttempts:
|
||||
log.warn('Failed to connect to %s too many times. '
|
||||
'Declare PMS dead' % url)
|
||||
LOG.warn('Failed to connect to %s too many times. '
|
||||
'Declare PMS dead', url)
|
||||
window('plex_online', value="false")
|
||||
except:
|
||||
# 'countError' not yet set
|
||||
|
|
Loading…
Reference in a new issue