Implement Codacy suggestions
This commit is contained in:
parent
1dbeb95e24
commit
2c77bd28af
16 changed files with 65 additions and 72 deletions
|
@ -62,7 +62,7 @@ class ImageCachingThread(backgroundthread.KillableThread):
|
||||||
LOG.info("---===### Starting ImageCachingThread ###===---")
|
LOG.info("---===### Starting ImageCachingThread ###===---")
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
except:
|
except Exception:
|
||||||
utils.ERROR()
|
utils.ERROR()
|
||||||
finally:
|
finally:
|
||||||
LOG.info("---===### Stopped ImageCachingThread ###===---")
|
LOG.info("---===### Stopped ImageCachingThread ###===---")
|
||||||
|
|
|
@ -131,12 +131,12 @@ class Tasks(list):
|
||||||
|
|
||||||
class Task(object):
|
class Task(object):
|
||||||
def __init__(self, priority=None):
|
def __init__(self, priority=None):
|
||||||
self._priority = priority
|
self.priority = priority
|
||||||
self._canceled = False
|
self._canceled = False
|
||||||
self.finished = False
|
self.finished = False
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
return self._priority - other._priority
|
return self.priority - other.priority
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
BGThreader.addTask(self)
|
BGThreader.addTask(self)
|
||||||
|
@ -182,7 +182,7 @@ class MutablePriorityQueue(Queue.PriorityQueue):
|
||||||
self.mutex.acquire()
|
self.mutex.acquire()
|
||||||
try:
|
try:
|
||||||
lowest = self.queue and min(self.queue) or None
|
lowest = self.queue and min(self.queue) or None
|
||||||
except:
|
except Exception:
|
||||||
lowest = None
|
lowest = None
|
||||||
utils.ERROR()
|
utils.ERROR()
|
||||||
finally:
|
finally:
|
||||||
|
@ -203,7 +203,7 @@ class BackgroundWorker(object):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
task._run()
|
task._run()
|
||||||
except:
|
except Exception:
|
||||||
utils.ERROR()
|
utils.ERROR()
|
||||||
|
|
||||||
def abort(self):
|
def abort(self):
|
||||||
|
@ -275,12 +275,12 @@ class BackgroundThreader:
|
||||||
self.name = name
|
self.name = name
|
||||||
self._queue = MutablePriorityQueue()
|
self._queue = MutablePriorityQueue()
|
||||||
self._abort = False
|
self._abort = False
|
||||||
self._priority = -1
|
self.priority = -1
|
||||||
self.workers = [worker(self._queue, 'queue.{0}:worker.{1}'.format(self.name, x)) for x in range(worker_count)]
|
self.workers = [worker(self._queue, 'queue.{0}:worker.{1}'.format(self.name, x)) for x in range(worker_count)]
|
||||||
|
|
||||||
def _nextPriority(self):
|
def _nextPriority(self):
|
||||||
self._priority += 1
|
self.priority += 1
|
||||||
return self._priority
|
return self.priority
|
||||||
|
|
||||||
def abort(self):
|
def abort(self):
|
||||||
self._abort = True
|
self._abort = True
|
||||||
|
@ -298,13 +298,13 @@ class BackgroundThreader:
|
||||||
w.shutdown()
|
w.shutdown()
|
||||||
|
|
||||||
def addTask(self, task):
|
def addTask(self, task):
|
||||||
task._priority = self._nextPriority()
|
task.priority = self._nextPriority()
|
||||||
self._queue.put(task)
|
self._queue.put(task)
|
||||||
self.startWorkers()
|
self.startWorkers()
|
||||||
|
|
||||||
def addTasks(self, tasks):
|
def addTasks(self, tasks):
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
t._priority = self._nextPriority()
|
t.priority = self._nextPriority()
|
||||||
self._queue.put(t)
|
self._queue.put(t)
|
||||||
|
|
||||||
self.startWorkers()
|
self.startWorkers()
|
||||||
|
@ -316,7 +316,7 @@ class BackgroundThreader:
|
||||||
|
|
||||||
p = lowest - len(tasks)
|
p = lowest - len(tasks)
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
t._priority = p
|
t.priority = p
|
||||||
self._queue.put(t)
|
self._queue.put(t)
|
||||||
p += 1
|
p += 1
|
||||||
|
|
||||||
|
@ -337,14 +337,14 @@ class BackgroundThreader:
|
||||||
if not lowest:
|
if not lowest:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return lowest._priority
|
return lowest.priority
|
||||||
|
|
||||||
def moveToFront(self, qitem):
|
def moveToFront(self, qitem):
|
||||||
lowest = self.getLowestPrority()
|
lowest = self.getLowestPrority()
|
||||||
if lowest is None:
|
if lowest is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
qitem._priority = lowest - 1
|
qitem.priority = lowest - 1
|
||||||
|
|
||||||
|
|
||||||
class ThreaderManager:
|
class ThreaderManager:
|
||||||
|
|
|
@ -84,21 +84,23 @@ class DownloadUtils():
|
||||||
def stopSession(self):
|
def stopSession(self):
|
||||||
try:
|
try:
|
||||||
self.s.close()
|
self.s.close()
|
||||||
except:
|
except Exception:
|
||||||
LOG.info("Requests session already closed")
|
LOG.info("Requests session already closed")
|
||||||
try:
|
try:
|
||||||
del self.s
|
del self.s
|
||||||
except:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
LOG.info('Request session stopped')
|
LOG.info('Request session stopped')
|
||||||
|
|
||||||
def getHeader(self, options=None):
|
@staticmethod
|
||||||
|
def getHeader(options=None):
|
||||||
header = clientinfo.getXArgsDeviceInfo()
|
header = clientinfo.getXArgsDeviceInfo()
|
||||||
if options is not None:
|
if options is not None:
|
||||||
header.update(options)
|
header.update(options)
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def _doDownload(self, s, action_type, **kwargs):
|
@staticmethod
|
||||||
|
def _doDownload(s, action_type, **kwargs):
|
||||||
if action_type == "GET":
|
if action_type == "GET":
|
||||||
r = s.get(**kwargs)
|
r = s.get(**kwargs)
|
||||||
elif action_type == "POST":
|
elif action_type == "POST":
|
||||||
|
@ -201,7 +203,7 @@ class DownloadUtils():
|
||||||
LOG.info('SystemExit detected, aborting download')
|
LOG.info('SystemExit detected, aborting download')
|
||||||
self.stopSession()
|
self.stopSession()
|
||||||
|
|
||||||
except:
|
except Exception:
|
||||||
LOG.warn('Unknown error while downloading. Traceback:')
|
LOG.warn('Unknown error while downloading. Traceback:')
|
||||||
import traceback
|
import traceback
|
||||||
LOG.warn(traceback.format_exc())
|
LOG.warn(traceback.format_exc())
|
||||||
|
@ -255,7 +257,7 @@ class DownloadUtils():
|
||||||
# xml response
|
# xml response
|
||||||
r = utils.defused_etree.fromstring(r.content)
|
r = utils.defused_etree.fromstring(r.content)
|
||||||
return r
|
return r
|
||||||
except:
|
except Exception:
|
||||||
r.encoding = 'utf-8'
|
r.encoding = 'utf-8'
|
||||||
if r.text == '':
|
if r.text == '':
|
||||||
# Answer does not contain a body
|
# Answer does not contain a body
|
||||||
|
@ -264,7 +266,7 @@ class DownloadUtils():
|
||||||
# UNICODE - JSON object
|
# UNICODE - JSON object
|
||||||
r = r.json()
|
r = r.json()
|
||||||
return r
|
return r
|
||||||
except:
|
except Exception:
|
||||||
if '200 OK' in r.text:
|
if '200 OK' in r.text:
|
||||||
# Received fucked up OK from PMS on playstate
|
# Received fucked up OK from PMS on playstate
|
||||||
# update
|
# update
|
||||||
|
|
|
@ -694,7 +694,7 @@ class KodiVideoDB(common.KodiDBBase):
|
||||||
SET tag_id = ?
|
SET tag_id = ?
|
||||||
WHERE media_id = ? AND media_type = ? AND tag_id = ?
|
WHERE media_id = ? AND media_type = ? AND tag_id = ?
|
||||||
''', (newtag, kodiid, mediatype, oldtag,))
|
''', (newtag, kodiid, mediatype, oldtag,))
|
||||||
except:
|
except Exception:
|
||||||
# The new tag we are going to apply already exists for this item
|
# The new tag we are going to apply already exists for this item
|
||||||
# delete current tag instead
|
# delete current tag instead
|
||||||
self.cursor.execute('''
|
self.cursor.execute('''
|
||||||
|
|
|
@ -41,7 +41,7 @@ class FanartThread(backgroundthread.KillableThread):
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self._run_internal()
|
self._run_internal()
|
||||||
except:
|
except Exception:
|
||||||
utils.ERROR(notify=True)
|
utils.ERROR(notify=True)
|
||||||
|
|
||||||
def _run_internal(self):
|
def _run_internal(self):
|
||||||
|
|
|
@ -65,6 +65,10 @@ class FullSync(common.fullsync_mixin):
|
||||||
self.title = ''
|
self.title = ''
|
||||||
self.section = None
|
self.section = None
|
||||||
self.section_name = None
|
self.section_name = None
|
||||||
|
self.section_type_text = None
|
||||||
|
self.context = None
|
||||||
|
self.get_children = None
|
||||||
|
self.successful = None
|
||||||
self.install_sync_done = utils.settings('SyncInstallRunDone') == 'true'
|
self.install_sync_done = utils.settings('SyncInstallRunDone') == 'true'
|
||||||
self.threader = backgroundthread.ThreaderManager(
|
self.threader = backgroundthread.ThreaderManager(
|
||||||
worker=backgroundthread.NonstoppingBackgroundWorker,
|
worker=backgroundthread.NonstoppingBackgroundWorker,
|
||||||
|
@ -181,7 +185,7 @@ class FullSync(common.fullsync_mixin):
|
||||||
while True:
|
while True:
|
||||||
# Check Plex DB to see what we need to add/update
|
# Check Plex DB to see what we need to add/update
|
||||||
with PlexDB() as self.plexdb:
|
with PlexDB() as self.plexdb:
|
||||||
for i, (last, xml_item) in enumerate(loop):
|
for last, xml_item in loop:
|
||||||
if self.isCanceled():
|
if self.isCanceled():
|
||||||
return False
|
return False
|
||||||
self.process_item(xml_item)
|
self.process_item(xml_item)
|
||||||
|
@ -428,7 +432,4 @@ class FullSync(common.fullsync_mixin):
|
||||||
|
|
||||||
|
|
||||||
def start(show_dialog, repair=False, callback=None):
|
def start(show_dialog, repair=False, callback=None):
|
||||||
"""
|
|
||||||
"""
|
|
||||||
# FullSync(repair, callback, show_dialog).start()
|
|
||||||
FullSync(repair, callback, show_dialog).run()
|
FullSync(repair, callback, show_dialog).run()
|
||||||
|
|
|
@ -15,7 +15,8 @@ LOG = getLogger('PLEX.videonodes')
|
||||||
|
|
||||||
class VideoNodes(object):
|
class VideoNodes(object):
|
||||||
|
|
||||||
def commonRoot(self, order, label, tagname, roottype=1):
|
@staticmethod
|
||||||
|
def commonRoot(order, label, tagname, roottype=1):
|
||||||
|
|
||||||
if roottype == 0:
|
if roottype == 0:
|
||||||
# Index
|
# Index
|
||||||
|
@ -113,10 +114,7 @@ class VideoNodes(object):
|
||||||
label=tagname,
|
label=tagname,
|
||||||
tagname=tagname,
|
tagname=tagname,
|
||||||
roottype=0)
|
roottype=0)
|
||||||
try:
|
utils.indent(root)
|
||||||
utils.indent(root)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
|
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
|
||||||
|
|
||||||
nodetypes = {
|
nodetypes = {
|
||||||
|
@ -406,10 +404,7 @@ class VideoNodes(object):
|
||||||
rule = etree.SubElement(root,
|
rule = etree.SubElement(root,
|
||||||
'rule',
|
'rule',
|
||||||
{'field': "inprogress", 'operator':"true"})
|
{'field': "inprogress", 'operator':"true"})
|
||||||
try:
|
utils.indent(root)
|
||||||
utils.indent(root)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
etree.ElementTree(root).write(path_ops.encode_path(nodeXML),
|
etree.ElementTree(root).write(path_ops.encode_path(nodeXML),
|
||||||
encoding="UTF-8")
|
encoding="UTF-8")
|
||||||
|
|
||||||
|
@ -464,13 +459,11 @@ class VideoNodes(object):
|
||||||
|
|
||||||
etree.SubElement(root, 'content').text = mediatype
|
etree.SubElement(root, 'content').text = mediatype
|
||||||
|
|
||||||
try:
|
utils.indent(root)
|
||||||
utils.indent(root)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
|
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
|
||||||
|
|
||||||
def clearProperties(self):
|
@staticmethod
|
||||||
|
def clearProperties():
|
||||||
|
|
||||||
LOG.info("Clearing nodes properties.")
|
LOG.info("Clearing nodes properties.")
|
||||||
plexprops = utils.window('Plex.nodes.total')
|
plexprops = utils.window('Plex.nodes.total')
|
||||||
|
|
|
@ -495,12 +495,6 @@ class API(object):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def votecount(self):
|
|
||||||
"""
|
|
||||||
Not yet implemented
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tagline(self):
|
def tagline(self):
|
||||||
"""
|
"""
|
||||||
Returns a shorter tagline or None
|
Returns a shorter tagline or None
|
||||||
|
@ -1517,7 +1511,7 @@ class API(object):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
date = sub(r'(\d+)-(\d+)-(\d+)', r'\3.\2.\1', date)
|
date = sub(r'(\d+)-(\d+)-(\d+)', r'\3.\2.\1', date)
|
||||||
except:
|
except Exception:
|
||||||
date = None
|
date = None
|
||||||
return date
|
return date
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
||||||
listener.MyHandler)
|
listener.MyHandler)
|
||||||
httpd.timeout = 0.95
|
httpd.timeout = 0.95
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
LOG.error("Unable to start PlexCompanion. Traceback:")
|
LOG.error("Unable to start PlexCompanion. Traceback:")
|
||||||
import traceback
|
import traceback
|
||||||
LOG.error(traceback.print_exc())
|
LOG.error(traceback.print_exc())
|
||||||
|
@ -330,7 +330,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
||||||
subscription_manager.notify()
|
subscription_manager.notify()
|
||||||
if not httpd:
|
if not httpd:
|
||||||
message_count = 0
|
message_count = 0
|
||||||
except:
|
except Exception:
|
||||||
LOG.warn("Error in loop, continuing anyway. Traceback:")
|
LOG.warn("Error in loop, continuing anyway. Traceback:")
|
||||||
import traceback
|
import traceback
|
||||||
LOG.warn(traceback.format_exc())
|
LOG.warn(traceback.format_exc())
|
||||||
|
|
|
@ -70,7 +70,7 @@ class RequestMgr:
|
||||||
# Close connection just in case
|
# Close connection just in case
|
||||||
try:
|
try:
|
||||||
conn.close()
|
conn.close()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ class MyHandler(BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(body)
|
self.wfile.write(body)
|
||||||
self.wfile.close()
|
self.wfile.close()
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def answer_request(self, send_data):
|
def answer_request(self, send_data):
|
||||||
|
|
|
@ -95,7 +95,7 @@ class plexgdm:
|
||||||
% (self.client_header, self.client_data),
|
% (self.client_header, self.client_data),
|
||||||
self.client_register_group)
|
self.client_register_group)
|
||||||
log.debug('(Re-)registering PKC Plex Companion successful')
|
log.debug('(Re-)registering PKC Plex Companion successful')
|
||||||
except:
|
except Exception:
|
||||||
log.error("Unable to send registration message")
|
log.error("Unable to send registration message")
|
||||||
|
|
||||||
def client_update(self):
|
def client_update(self):
|
||||||
|
@ -109,14 +109,14 @@ class plexgdm:
|
||||||
update_sock.setsockopt(socket.SOL_SOCKET,
|
update_sock.setsockopt(socket.SOL_SOCKET,
|
||||||
socket.SO_REUSEADDR,
|
socket.SO_REUSEADDR,
|
||||||
1)
|
1)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Attempt to bind to the socket to recieve and send data. If we cant
|
# Attempt to bind to the socket to recieve and send data. If we cant
|
||||||
# do this, then we cannot send registration
|
# do this, then we cannot send registration
|
||||||
try:
|
try:
|
||||||
update_sock.bind(('0.0.0.0', self.client_update_port))
|
update_sock.bind(('0.0.0.0', self.client_update_port))
|
||||||
except:
|
except Exception:
|
||||||
log.error("Unable to bind to port [%s] - Plex Companion will not "
|
log.error("Unable to bind to port [%s] - Plex Companion will not "
|
||||||
"be registered. Change the Plex Companion update port!"
|
"be registered. Change the Plex Companion update port!"
|
||||||
% self.client_update_port)
|
% self.client_update_port)
|
||||||
|
@ -165,7 +165,7 @@ class plexgdm:
|
||||||
update_sock.sendto("HTTP/1.0 200 OK\n%s"
|
update_sock.sendto("HTTP/1.0 200 OK\n%s"
|
||||||
% self.client_data,
|
% self.client_data,
|
||||||
addr)
|
addr)
|
||||||
except:
|
except Exception:
|
||||||
log.error("Unable to send client update message")
|
log.error("Unable to send client update message")
|
||||||
|
|
||||||
log.debug("Sending registration data HTTP/1.0 200 OK")
|
log.debug("Sending registration data HTTP/1.0 200 OK")
|
||||||
|
@ -180,7 +180,7 @@ class plexgdm:
|
||||||
update_sock.sendto("BYE %s\n%s"
|
update_sock.sendto("BYE %s\n%s"
|
||||||
% (self.client_header, self.client_data),
|
% (self.client_header, self.client_data),
|
||||||
self.client_register_group)
|
self.client_register_group)
|
||||||
except:
|
except Exception:
|
||||||
log.error("Unable to send client update message")
|
log.error("Unable to send client update message")
|
||||||
self.client_registered = False
|
self.client_registered = False
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ class Sync(backgroundthread.KillableThread):
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self._run_internal()
|
self._run_internal()
|
||||||
except:
|
except Exception:
|
||||||
app.SYNC.db_scan = False
|
app.SYNC.db_scan = False
|
||||||
utils.window('plex_dbScan', clear=True)
|
utils.window('plex_dbScan', clear=True)
|
||||||
utils.ERROR(txt='sync.py crashed', notify=True)
|
utils.ERROR(txt='sync.py crashed', notify=True)
|
||||||
|
|
|
@ -607,19 +607,22 @@ def indent(elem, level=0):
|
||||||
"""
|
"""
|
||||||
Prettifies xml trees. Pass the etree root in
|
Prettifies xml trees. Pass the etree root in
|
||||||
"""
|
"""
|
||||||
i = "\n" + level * " "
|
try:
|
||||||
if len(elem):
|
i = "\n" + level * " "
|
||||||
if not elem.text or not elem.text.strip():
|
if len(elem):
|
||||||
elem.text = i + " "
|
if not elem.text or not elem.text.strip():
|
||||||
if not elem.tail or not elem.tail.strip():
|
elem.text = i + " "
|
||||||
elem.tail = i
|
if not elem.tail or not elem.tail.strip():
|
||||||
for elem in elem:
|
elem.tail = i
|
||||||
indent(elem, level + 1)
|
for elem in elem:
|
||||||
if not elem.tail or not elem.tail.strip():
|
indent(elem, level + 1)
|
||||||
elem.tail = i
|
if not elem.tail or not elem.tail.strip():
|
||||||
else:
|
elem.tail = i
|
||||||
if level and (not elem.tail or not elem.tail.strip()):
|
else:
|
||||||
elem.tail = i
|
if level and (not elem.tail or not elem.tail.strip()):
|
||||||
|
elem.tail = i
|
||||||
|
except Exception as err:
|
||||||
|
LOG.info('Indentation failed with: %s', err)
|
||||||
|
|
||||||
|
|
||||||
class XmlKodiSetting(object):
|
class XmlKodiSetting(object):
|
||||||
|
|
|
@ -705,7 +705,7 @@ class WebSocket(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.sock.shutdown(socket.SHUT_RDWR)
|
self.sock.shutdown(socket.SHUT_RDWR)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
self._closeInternal()
|
self._closeInternal()
|
||||||
|
|
||||||
|
|
|
@ -237,7 +237,7 @@ class Alexa_Websocket(WebSocket):
|
||||||
LOG.error('%s: Unknown Alexa message received',
|
LOG.error('%s: Unknown Alexa message received',
|
||||||
self.__class__.__name__)
|
self.__class__.__name__)
|
||||||
return
|
return
|
||||||
except:
|
except Exception:
|
||||||
LOG.error('%s: Could not parse Alexa message',
|
LOG.error('%s: Could not parse Alexa message',
|
||||||
self.__class__.__name__)
|
self.__class__.__name__)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue