Merge pull request #684 from croneter/codacy

Implement Codacy suggestions
This commit is contained in:
croneter 2019-02-03 20:23:49 +01:00 committed by GitHub
commit 4edea1c7a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 65 additions and 72 deletions

View file

@ -62,7 +62,7 @@ class ImageCachingThread(backgroundthread.KillableThread):
LOG.info("---===### Starting ImageCachingThread ###===---")
try:
self._run()
except:
except Exception:
utils.ERROR()
finally:
LOG.info("---===### Stopped ImageCachingThread ###===---")

View file

@ -131,12 +131,12 @@ class Tasks(list):
class Task(object):
def __init__(self, priority=None):
self._priority = priority
self.priority = priority
self._canceled = False
self.finished = False
def __cmp__(self, other):
return self._priority - other._priority
return self.priority - other.priority
def start(self):
BGThreader.addTask(self)
@ -182,7 +182,7 @@ class MutablePriorityQueue(Queue.PriorityQueue):
self.mutex.acquire()
try:
lowest = self.queue and min(self.queue) or None
except:
except Exception:
lowest = None
utils.ERROR()
finally:
@ -203,7 +203,7 @@ class BackgroundWorker(object):
return
try:
task._run()
except:
except Exception:
utils.ERROR()
def abort(self):
@ -275,12 +275,12 @@ class BackgroundThreader:
self.name = name
self._queue = MutablePriorityQueue()
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)]
def _nextPriority(self):
self._priority += 1
return self._priority
self.priority += 1
return self.priority
def abort(self):
self._abort = True
@ -298,13 +298,13 @@ class BackgroundThreader:
w.shutdown()
def addTask(self, task):
task._priority = self._nextPriority()
task.priority = self._nextPriority()
self._queue.put(task)
self.startWorkers()
def addTasks(self, tasks):
for t in tasks:
t._priority = self._nextPriority()
t.priority = self._nextPriority()
self._queue.put(t)
self.startWorkers()
@ -316,7 +316,7 @@ class BackgroundThreader:
p = lowest - len(tasks)
for t in tasks:
t._priority = p
t.priority = p
self._queue.put(t)
p += 1
@ -337,14 +337,14 @@ class BackgroundThreader:
if not lowest:
return None
return lowest._priority
return lowest.priority
def moveToFront(self, qitem):
lowest = self.getLowestPrority()
if lowest is None:
return
qitem._priority = lowest - 1
qitem.priority = lowest - 1
class ThreaderManager:

View file

@ -84,21 +84,23 @@ class DownloadUtils():
def stopSession(self):
try:
self.s.close()
except:
except Exception:
LOG.info("Requests session already closed")
try:
del self.s
except:
except AttributeError:
pass
LOG.info('Request session stopped')
def getHeader(self, options=None):
@staticmethod
def getHeader(options=None):
header = clientinfo.getXArgsDeviceInfo()
if options is not None:
header.update(options)
return header
def _doDownload(self, s, action_type, **kwargs):
@staticmethod
def _doDownload(s, action_type, **kwargs):
if action_type == "GET":
r = s.get(**kwargs)
elif action_type == "POST":
@ -201,7 +203,7 @@ class DownloadUtils():
LOG.info('SystemExit detected, aborting download')
self.stopSession()
except:
except Exception:
LOG.warn('Unknown error while downloading. Traceback:')
import traceback
LOG.warn(traceback.format_exc())
@ -255,7 +257,7 @@ class DownloadUtils():
# xml response
r = utils.defused_etree.fromstring(r.content)
return r
except:
except Exception:
r.encoding = 'utf-8'
if r.text == '':
# Answer does not contain a body
@ -264,7 +266,7 @@ class DownloadUtils():
# UNICODE - JSON object
r = r.json()
return r
except:
except Exception:
if '200 OK' in r.text:
# Received fucked up OK from PMS on playstate
# update

View file

@ -694,7 +694,7 @@ class KodiVideoDB(common.KodiDBBase):
SET tag_id = ?
WHERE media_id = ? AND media_type = ? AND tag_id = ?
''', (newtag, kodiid, mediatype, oldtag,))
except:
except Exception:
# The new tag we are going to apply already exists for this item
# delete current tag instead
self.cursor.execute('''

View file

@ -41,7 +41,7 @@ class FanartThread(backgroundthread.KillableThread):
def run(self):
try:
self._run_internal()
except:
except Exception:
utils.ERROR(notify=True)
def _run_internal(self):

View file

@ -65,6 +65,10 @@ class FullSync(common.fullsync_mixin):
self.title = ''
self.section = 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.threader = backgroundthread.ThreaderManager(
worker=backgroundthread.NonstoppingBackgroundWorker,
@ -181,7 +185,7 @@ class FullSync(common.fullsync_mixin):
while True:
# Check Plex DB to see what we need to add/update
with PlexDB() as self.plexdb:
for i, (last, xml_item) in enumerate(loop):
for last, xml_item in loop:
if self.isCanceled():
return False
self.process_item(xml_item)
@ -428,7 +432,4 @@ class FullSync(common.fullsync_mixin):
def start(show_dialog, repair=False, callback=None):
"""
"""
# FullSync(repair, callback, show_dialog).start()
FullSync(repair, callback, show_dialog).run()

View file

@ -15,7 +15,8 @@ LOG = getLogger('PLEX.videonodes')
class VideoNodes(object):
def commonRoot(self, order, label, tagname, roottype=1):
@staticmethod
def commonRoot(order, label, tagname, roottype=1):
if roottype == 0:
# Index
@ -113,10 +114,7 @@ class VideoNodes(object):
label=tagname,
tagname=tagname,
roottype=0)
try:
utils.indent(root)
except:
pass
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
nodetypes = {
@ -406,10 +404,7 @@ class VideoNodes(object):
rule = etree.SubElement(root,
'rule',
{'field': "inprogress", 'operator':"true"})
try:
utils.indent(root)
except:
pass
etree.ElementTree(root).write(path_ops.encode_path(nodeXML),
encoding="UTF-8")
@ -464,13 +459,11 @@ class VideoNodes(object):
etree.SubElement(root, 'content').text = mediatype
try:
utils.indent(root)
except:
pass
etree.ElementTree(root).write(nodeXML, encoding="UTF-8")
def clearProperties(self):
@staticmethod
def clearProperties():
LOG.info("Clearing nodes properties.")
plexprops = utils.window('Plex.nodes.total')

View file

@ -495,12 +495,6 @@ class API(object):
"""
pass
def votecount(self):
"""
Not yet implemented
"""
pass
def tagline(self):
"""
Returns a shorter tagline or None
@ -1517,7 +1511,7 @@ class API(object):
return
try:
date = sub(r'(\d+)-(\d+)-(\d+)', r'\3.\2.\1', date)
except:
except Exception:
date = None
return date

View file

@ -282,7 +282,7 @@ class PlexCompanion(backgroundthread.KillableThread):
listener.MyHandler)
httpd.timeout = 0.95
break
except:
except Exception:
LOG.error("Unable to start PlexCompanion. Traceback:")
import traceback
LOG.error(traceback.print_exc())
@ -330,7 +330,7 @@ class PlexCompanion(backgroundthread.KillableThread):
subscription_manager.notify()
if not httpd:
message_count = 0
except:
except Exception:
LOG.warn("Error in loop, continuing anyway. Traceback:")
import traceback
LOG.warn(traceback.format_exc())

View file

@ -70,7 +70,7 @@ class RequestMgr:
# Close connection just in case
try:
conn.close()
except:
except Exception:
pass
return False

View file

@ -93,7 +93,7 @@ class MyHandler(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(body)
self.wfile.close()
except:
except Exception:
pass
def answer_request(self, send_data):

View file

@ -95,7 +95,7 @@ class plexgdm:
% (self.client_header, self.client_data),
self.client_register_group)
log.debug('(Re-)registering PKC Plex Companion successful')
except:
except Exception:
log.error("Unable to send registration message")
def client_update(self):
@ -109,14 +109,14 @@ class plexgdm:
update_sock.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR,
1)
except:
except Exception:
pass
# Attempt to bind to the socket to recieve and send data. If we cant
# do this, then we cannot send registration
try:
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 "
"be registered. Change the Plex Companion update port!"
% self.client_update_port)
@ -165,7 +165,7 @@ class plexgdm:
update_sock.sendto("HTTP/1.0 200 OK\n%s"
% self.client_data,
addr)
except:
except Exception:
log.error("Unable to send client update message")
log.debug("Sending registration data HTTP/1.0 200 OK")
@ -180,7 +180,7 @@ class plexgdm:
update_sock.sendto("BYE %s\n%s"
% (self.client_header, self.client_data),
self.client_register_group)
except:
except Exception:
log.error("Unable to send client update message")
self.client_registered = False

View file

@ -146,7 +146,7 @@ class Sync(backgroundthread.KillableThread):
def run(self):
try:
self._run_internal()
except:
except Exception:
app.SYNC.db_scan = False
utils.window('plex_dbScan', clear=True)
utils.ERROR(txt='sync.py crashed', notify=True)

View file

@ -607,6 +607,7 @@ def indent(elem, level=0):
"""
Prettifies xml trees. Pass the etree root in
"""
try:
i = "\n" + level * " "
if len(elem):
if not elem.text or not elem.text.strip():
@ -620,6 +621,8 @@ def indent(elem, level=0):
else:
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):

View file

@ -705,7 +705,7 @@ class WebSocket(object):
"""
try:
self.sock.shutdown(socket.SHUT_RDWR)
except:
except Exception:
pass
self._closeInternal()

View file

@ -237,7 +237,7 @@ class Alexa_Websocket(WebSocket):
LOG.error('%s: Unknown Alexa message received',
self.__class__.__name__)
return
except:
except Exception:
LOG.error('%s: Could not parse Alexa message',
self.__class__.__name__)
return