Implement Codacy suggestions

This commit is contained in:
croneter 2019-02-08 13:52:33 +01:00
parent f24266fb54
commit e6cd80a7dd
11 changed files with 50 additions and 26 deletions

View file

@ -92,7 +92,7 @@ class Connection(object):
LOG.debug('Clearing connection settings')
self.machine_identifier = None
self.server_name = None
self.http = None
self.https = None
self.host = None
self.port = None
self.server = None

View file

@ -37,7 +37,8 @@ class ImageCachingThread(backgroundthread.KillableThread):
def isSuspended(self):
return any(self.suspend_points)
def _url_generator(self, kind, kodi_type):
@staticmethod
def _url_generator(kind, kodi_type):
"""
Main goal is to close DB connection between calls
"""

View file

@ -225,7 +225,8 @@ class BackgroundWorker(object):
self._abort = False
self._task = None
def _runTask(self, task):
@staticmethod
def _runTask(task):
if task._canceled:
return
try:

View file

@ -69,7 +69,8 @@ class InitialSetup(object):
utils.settings('plex_allows_mediaDeletion', value=value)
utils.window('plex_allows_mediaDeletion', value=value)
def enter_new_pms_address(self):
@staticmethod
def enter_new_pms_address():
LOG.info('Start getting manual PMS address and port')
# "Enter your Plex Media Server's IP or URL. Examples are:"
utils.messageDialog(utils.lang(29999),
@ -196,12 +197,12 @@ class InitialSetup(object):
LOG.error('Failed to update Plex info from plex.tv')
else:
utils.settings('plexLogin', value=self.plex_login)
home = 'true' if xml.attrib.get('home') == '1' else 'false'
utils.settings('plexAvatar', value=xml.attrib.get('thumb'))
LOG.info('Updated Plex info from plex.tv')
return answer
def check_existing_pms(self):
@staticmethod
def check_existing_pms():
"""
Check the PMS that was set in file settings.
Will return False if we need to reconnect, because:

View file

@ -207,7 +207,8 @@ class KodiMonitor(xbmc.Monitor):
"""
pass
def _playlist_onclear(self, data):
@staticmethod
def _playlist_onclear(data):
"""
Called if a Kodi playlist is cleared. Example data dict:
{
@ -221,7 +222,8 @@ class KodiMonitor(xbmc.Monitor):
else:
LOG.debug('Detected PKC clear - ignoring')
def _get_ids(self, kodi_id, kodi_type, path):
@staticmethod
def _get_ids(kodi_id, kodi_type, path):
"""
Returns the tuple (plex_id, plex_type) or (None, None)
"""
@ -315,7 +317,7 @@ class KodiMonitor(xbmc.Monitor):
return
playerid = js.get_playlist_id(playlist_type)
if not playerid:
LOG.error('Coud not get playerid for data', data)
LOG.error('Coud not get playerid for data %s', data)
return
playqueue = PQ.PLAYQUEUES[playerid]
info = js.get_player_props(playerid)

View file

@ -147,7 +147,8 @@ class PlayUtils():
return False
return True
def get_max_bitrate(self):
@staticmethod
def get_max_bitrate():
# get the addon video quality
videoQuality = utils.settings('maxVideoQualities')
bitrate = {
@ -167,7 +168,8 @@ class PlayUtils():
# max bit rate supported by server (max signed 32bit integer)
return bitrate.get(videoQuality, 2147483)
def getH265(self):
@staticmethod
def getH265():
"""
Returns the user settings for transcoding h265: boundary resolutions
of 480, 720 or 1080 as an int
@ -182,7 +184,8 @@ class PlayUtils():
}
return H265[utils.settings('transcodeH265')]
def get_bitrate(self):
@staticmethod
def get_bitrate():
"""
Get the desired transcoding bitrate from the settings
"""
@ -203,7 +206,8 @@ class PlayUtils():
# max bit rate supported by server (max signed 32bit integer)
return bitrate.get(videoQuality, 2147483)
def get_resolution(self):
@staticmethod
def get_resolution():
"""
Get the desired transcoding resolutions from the settings
"""

View file

@ -80,7 +80,8 @@ class PlexCompanion(backgroundthread.KillableThread):
self.subscription_manager = None
super(PlexCompanion, self).__init__()
def _process_alexa(self, data):
@staticmethod
def _process_alexa(data):
xml = PF.GetPlexMetadata(data['key'])
try:
xml[0].attrib
@ -135,7 +136,8 @@ class PlexCompanion(backgroundthread.KillableThread):
executebuiltin('RunPlugin(plugin://%s?%s)'
% (v.ADDON_ID, urlencode(params)))
def _process_playlist(self, data):
@staticmethod
def _process_playlist(data):
# Get the playqueue ID
_, container_key, query = PF.ParseContainerKey(data['containerKey'])
try:
@ -159,7 +161,8 @@ class PlexCompanion(backgroundthread.KillableThread):
offset=data.get('offset'),
transient_token=data.get('token'))
def _process_streams(self, data):
@staticmethod
def _process_streams(data):
"""
Plex Companion client adjusted audio or subtitle stream
"""
@ -180,7 +183,8 @@ class PlexCompanion(backgroundthread.KillableThread):
else:
LOG.error('Unknown setStreams command: %s', data)
def _process_refresh(self, data):
@staticmethod
def _process_refresh(data):
"""
example data: {'playQueueID': '8475', 'commandID': '11'}
"""

View file

@ -45,6 +45,9 @@ class plexgdm:
self.discover_message = 'M-SEARCH * HTTP/1.0'
self.client_header = '* HTTP/1.0'
self.client_data = None
self.update_sock = None
self.discover_t = None
self.register_t = None
self._multicast_address = '239.0.0.250'
self.discover_group = (self._multicast_address, 32414)

View file

@ -107,12 +107,16 @@ class Service():
self.server_has_been_online = True
self.welcome_msg = True
self.connection_check_counter = 0
self.setup = None
self.alexa = None
self.playqueue = None
# Flags for other threads
self.connection_check_running = False
self.auth_running = False
self._init_done = True
def isCanceled(self):
@staticmethod
def isCanceled():
return xbmc.abortRequested or app.APP.stop_pkc
def on_connection_check(self, result):
@ -170,7 +174,8 @@ class Service():
finally:
self.connection_check_running = False
def log_out(self):
@staticmethod
def log_out():
"""
Ensures that lib sync threads are suspended; signs out user
"""

View file

@ -206,7 +206,7 @@ class ControlledWindow(ControlledBase, BaseWindow):
if action in (xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK):
self.doClose()
return
except:
except Exception:
traceback.print_exc()
BaseWindow.onAction(self, action)
@ -218,7 +218,7 @@ class ControlledDialog(ControlledBase, BaseDialog):
if action in (xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK):
self.doClose()
return
except:
except Exception:
traceback.print_exc()
BaseDialog.onAction(self, action)
@ -228,7 +228,8 @@ DUMMY_LIST_ITEM = xbmcgui.ListItem()
class ManagedListItem(object):
def __init__(self, label='', label2='', iconImage='', thumbnailImage='', path='', data_source=None, properties=None):
def __init__(self, label='', label2='', iconImage='', thumbnailImage='',
path='', data_source=None, properties=None):
self._listItem = xbmcgui.ListItem(label, label2, iconImage, thumbnailImage, path)
self.dataSource = data_source
self.properties = {}
@ -608,13 +609,15 @@ class ManagedControlList(object):
def getViewPosition(self):
try:
return int(xbmc.getInfoLabel('Container({0}).Position'.format(self.controlID)))
except:
except Exception:
return 0
def getViewRange(self):
viewPosition = self.getViewPosition()
selected = self.getSelectedPosition()
return range(max(selected - viewPosition, 0), min(selected + (self._maxViewIndex - viewPosition) + 1, self.size() - 1))
return range(max(selected - viewPosition, 0),
min(selected + (self._maxViewIndex - viewPosition) + 1,
self.size() - 1))
def positionIsValid(self, pos):
return 0 <= pos < self.size()
@ -809,7 +812,7 @@ class SafeControlEdit(object):
if self.processOffControlAction(action.getButtonCode()):
self._win.setFocusId(self.controlID)
return
except:
except Exception:
traceback.print_exc()
self._winOnAction(action)