From 8b9b0821c0ad2c1a67b997c6f2edd9a92febce67 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sun, 21 Aug 2016 21:51:23 -0500 Subject: [PATCH] Pylint (testing) --- resources/lib/artwork.py | 12 +++---- resources/lib/image_cache_thread.py | 55 +++++++++++++++-------------- resources/lib/loghandler.py | 19 +++++----- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/resources/lib/artwork.py b/resources/lib/artwork.py index a9ca780c..28ace1fa 100644 --- a/resources/lib/artwork.py +++ b/resources/lib/artwork.py @@ -254,7 +254,7 @@ class Artwork(): while len(self.imageCacheThreads): for thread in self.imageCacheThreads: - if thread.isFinished: + if thread.is_finished: self.imageCacheThreads.remove(thread) pdialog.update(100, "%s %s" % (lang(33046), len(self.imageCacheThreads))) log.info("Waiting for all threads to exit: %s" % len(self.imageCacheThreads)) @@ -267,15 +267,15 @@ class Artwork(): while True: # removed finished for thread in self.imageCacheThreads: - if thread.isFinished: + if thread.is_finished: self.imageCacheThreads.remove(thread) # add a new thread or wait and retry if we hit our limit if len(self.imageCacheThreads) < self.imageCacheLimitThreads: - newThread = image_cache_thread.image_cache_thread() - newThread.setUrl(self.double_urlencode(url)) - newThread.setHost(self.xbmc_host, self.xbmc_port) - newThread.setAuth(self.xbmc_username, self.xbmc_password) + newThread = image_cache_thread.ImageCacheThread() + newThread.set_url(self.double_urlencode(url)) + newThread.set_host(self.xbmc_host, self.xbmc_port) + newThread.set_auth(self.xbmc_username, self.xbmc_password) newThread.start() self.imageCacheThreads.append(newThread) return diff --git a/resources/lib/image_cache_thread.py b/resources/lib/image_cache_thread.py index ffed967b..9f17f1f9 100644 --- a/resources/lib/image_cache_thread.py +++ b/resources/lib/image_cache_thread.py @@ -3,8 +3,8 @@ ################################################################################################# import logging -import requests import threading +import requests ################################################################################################# @@ -12,49 +12,50 @@ log = logging.getLogger("EMBY."+__name__) ################################################################################################# -class image_cache_thread(threading.Thread): +class ImageCacheThread(threading.Thread): + + url_to_process = None + is_finished = False - urlToProcess = None - isFinished = False - xbmc_host = "" xbmc_port = "" xbmc_username = "" xbmc_password = "" - + def __init__(self): threading.Thread.__init__(self) - - def setUrl(self, url): - self.urlToProcess = url - - def setHost(self, host, port): + def set_url(self, url): + + self.url_to_process = url + + def set_host(self, host, port): self.xbmc_host = host self.xbmc_port = port - - def setAuth(self, user, pwd): - self.xbmc_username = user - self.xbmc_password = pwd - + def set_auth(self, username, password): + + self.xbmc_username = username + self.xbmc_password = password + def run(self): - - log.debug("Image Caching Thread Processing: %s" % self.urlToProcess) + + log.debug("Image Caching Thread Processing: %s" % self.url_to_process) try: - response = requests.head( - url=( - "http://%s:%s/image/image://%s" - % (self.xbmc_host, self.xbmc_port, self.urlToProcess)), - auth=(self.xbmc_username, self.xbmc_password), - timeout=(35.1, 35.1)) + requests.head( + url=( + "http://%s:%s/image/image://%s" + % (self.xbmc_host, self.xbmc_port, self.url_to_process)), + auth=(self.xbmc_username, self.xbmc_password), + timeout=(35.1, 35.1)) # We don't need the result - except: pass - + except: + pass + log.debug("Image Caching Thread Exited") - self.isFinished = True \ No newline at end of file + self.is_finished = True diff --git a/resources/lib/loghandler.py b/resources/lib/loghandler.py index 9ae91f89..5169d361 100644 --- a/resources/lib/loghandler.py +++ b/resources/lib/loghandler.py @@ -11,7 +11,7 @@ from utils import window def config(): - + logger = logging.getLogger('EMBY') logger.addHandler(LogHandler()) logger.setLevel(logging.DEBUG) @@ -20,19 +20,20 @@ def config(): class LogHandler(logging.StreamHandler): def __init__(self): - + logging.StreamHandler.__init__(self) self.setFormatter(MyFormatter()) def emit(self, record): - if self._getLogLevel(record.levelno): + if self._get_log_level(record.levelno): try: xbmc.log(self.format(record), level=xbmc.LOGNOTICE) except UnicodeEncodeError: xbmc.log(self.format(record).encode('utf-8'), level=xbmc.LOGNOTICE) - def _getLogLevel(self, level): + @classmethod + def _get_log_level(cls, level): levels = { logging.ERROR: 0, @@ -41,17 +42,17 @@ class LogHandler(logging.StreamHandler): logging.DEBUG: 2 } try: - logLevel = int(window('emby_logLevel')) + log_level = int(window('emby_logLevel')) except ValueError: - logLevel = 0 + log_level = 0 - return logLevel >= levels[level] + return log_level >= levels[level] class MyFormatter(logging.Formatter): def __init__(self, fmt="%(name)s -> %(message)s"): - + logging.Formatter.__init__(self, fmt) def format(self, record): @@ -70,4 +71,4 @@ class MyFormatter(logging.Formatter): # Restore the original format configured by the user self._fmt = format_orig - return result \ No newline at end of file + return result