Commit 69cee253 authored by echel0n's avatar echel0n
Browse files

Misc code cleanup

parent a2aa3404
# Changelog
- * 4de0cac - 2018-08-18: Pre-Release v9.3.56.dev28
- * c9b0780 - 2018-08-19: Misc code cleanup
- * a2aa340 - 2018-08-18: Pre-Release v9.3.56.dev28
- * 10de224 - 2018-08-18: Pre-Release v9.3.56.dev27
- * 8efa7cb - 2018-08-18: Fixed broken toggle buttons
- * e27a959 - 2018-08-18: Fixed gaierror's for ssdp Fixed WebHandler routing errors
......
......@@ -44,69 +44,66 @@ class ShowQueue(srQueue):
srQueue.__init__(self, "SHOWQUEUE")
@property
def loadingShowList(self):
return self._getLoadingShowList()
def _isInQueue(self, show, actions):
if not show:
return False
def loading_show_list(self):
return self._get_loading_show_list()
def _is_in_queue(self, show, actions):
return show.indexerid in [x.show.indexerid if x.show else 0 for __, __, x in self.queue if
x.action_id in actions]
x.action_id in actions] if show else False
def _isBeing(self, show, actions):
def _is_being(self, show, actions):
return self.currentItem is not None and show == self.currentItem.show and self.currentItem.action_id in actions
def isInUpdateQueue(self, show):
return self._isInQueue(show, (ShowQueueActions.UPDATE, ShowQueueActions.FORCEUPDATE))
def is_in_update_queue(self, show):
return self._is_in_queue(show, (ShowQueueActions.UPDATE, ShowQueueActions.FORCEUPDATE))
def isInRefreshQueue(self, show):
return self._isInQueue(show, (ShowQueueActions.REFRESH,))
def is_in_refresh_queue(self, show):
return self._is_in_queue(show, (ShowQueueActions.REFRESH,))
def isInRenameQueue(self, show):
return self._isInQueue(show, (ShowQueueActions.RENAME,))
def is_in_rename_queue(self, show):
return self._is_in_queue(show, (ShowQueueActions.RENAME,))
def isInSubtitleQueue(self, show):
return self._isInQueue(show, (ShowQueueActions.SUBTITLE,))
def is_in_subtitle_queue(self, show):
return self._is_in_queue(show, (ShowQueueActions.SUBTITLE,))
def isBeingRemoved(self, show):
return self._isBeing(show, (ShowQueueActions.REMOVE,))
def is_being_removed(self, show):
return self._is_being(show, (ShowQueueActions.REMOVE,))
def isBeingAdded(self, show):
return self._isBeing(show, (ShowQueueActions.ADD,))
def is_being_added(self, show):
return self._is_being(show, (ShowQueueActions.ADD,))
def isBeingUpdated(self, show):
return self._isBeing(show, (ShowQueueActions.UPDATE, ShowQueueActions.FORCEUPDATE))
def is_being_updated(self, show):
return self._is_being(show, (ShowQueueActions.UPDATE, ShowQueueActions.FORCEUPDATE))
def isBeingRefreshed(self, show):
return self._isBeing(show, (ShowQueueActions.REFRESH,))
def is_being_refreshed(self, show):
return self._is_being(show, (ShowQueueActions.REFRESH,))
def isBeingRenamed(self, show):
return self._isBeing(show, (ShowQueueActions.RENAME,))
def is_being_renamed(self, show):
return self._is_being(show, (ShowQueueActions.RENAME,))
def isBeingSubtitled(self, show):
return self._isBeing(show, (ShowQueueActions.SUBTITLE,))
def is_being_subtitled(self, show):
return self._is_being(show, (ShowQueueActions.SUBTITLE,))
def _getLoadingShowList(self):
return [x for __, __, x in self.queue + [(None, None, self.currentItem)] if x and x.isLoading]
def _get_loading_show_list(self):
return [x for __, __, x in self.queue + [(None, None, self.currentItem)] if x and x.is_loading]
def updateShow(self, show, force=False):
if self.isBeingAdded(show):
if self.is_being_added(show):
raise CantUpdateShowException("{} is still being added, please wait until it is finished before trying to "
"update.".format(show.name))
if self.isBeingUpdated(show):
if self.is_being_updated(show):
raise CantUpdateShowException("{} is already being updated, can't update again until "
"it's done.".format(show.name))
if self.isInUpdateQueue(show):
if self.is_in_update_queue(show):
raise CantUpdateShowException("{} is in the process of being updated, can't update again until "
"it's done.".format(show.name))
return self.put(QueueItemForceUpdate(show)) if force else self.put(QueueItemUpdate(show))
def refreshShow(self, show, force=False):
if (self.isBeingRefreshed(show) or self.isInRefreshQueue(show)) and not force:
if (self.is_being_refreshed(show) or self.is_in_refresh_queue(show)) and not force:
raise CantRefreshShowException("This show is already being refreshed or queued to be refreshed, skipping "
"this request.")
......@@ -153,7 +150,7 @@ class ShowQueue(srQueue):
raise CantRemoveShowException('Failed removing show: Show does not exist')
elif not hasattr(show, 'indexerid'):
raise CantRemoveShowException('Failed removing show: Show does not have an indexer id')
elif self._isInQueue(show, (ShowQueueActions.REMOVE,)):
elif self._is_in_queue(show, (ShowQueueActions.REMOVE,)):
raise CantRemoveShowException("{} is already queued to be removed".format(show))
# remove other queued actions for this show.
......@@ -202,12 +199,11 @@ class ShowQueueItem(srQueueItem):
def __init__(self, show, action_id):
super(ShowQueueItem, self).__init__(ShowQueueActions.names[action_id], action_id)
self.show = show
self.startTime = time.time()
def finish(self):
self.show.flushEpisodes()
def isInQueue(self):
def is_in_queue(self):
return self in sickrage.app.show_queue.queue + [sickrage.app.show_queue.currentItem]
@property
......@@ -215,7 +211,7 @@ class ShowQueueItem(srQueueItem):
return str(self.show.indexerid)
@property
def isLoading(self):
def is_loading(self):
return False
......@@ -249,12 +245,10 @@ class QueueItemAdd(ShowQueueItem):
Returns the show name if there is a show object created, if not returns
the dir that the show is being added to.
"""
if self.show is None:
return os.path.basename(self.showDir)
return self.show.name
return self.show.name if self.show else os.path.basename(self.showDir)
@property
def isLoading(self):
def is_loading(self):
"""
Returns True if we've gotten far enough to have a show object, or False
if we still only know the folder name.
......@@ -263,6 +257,8 @@ class QueueItemAdd(ShowQueueItem):
return True
def run(self):
start_time = time.time()
sickrage.app.log.info("Started adding show {} from show dir: {}".format(self.show_name, self.showDir))
index_name = IndexerApi(self.indexer).name
......@@ -284,7 +280,7 @@ class QueueItemAdd(ShowQueueItem):
s = None
if not s:
return self._finishEarly()
return self._finish_early()
# this usually only happens if they have an NFO in their show dir which gave us a Indexer ID that has no proper english version of the show
if not getattr(s, 'seriesname'):
......@@ -295,7 +291,7 @@ class QueueItemAdd(ShowQueueItem):
_("Show in {} has no name on {}, probably the wrong language. Delete .nfo "
"and add manually in the correct language").format(self.showDir,
index_name))
return self._finishEarly()
return self._finish_early()
# if the show has no episodes/seasons
if not len(s):
......@@ -306,7 +302,7 @@ class QueueItemAdd(ShowQueueItem):
IndexerApi(
self.indexer).name) + _(
" but contains no season/episode data."))
return self._finishEarly()
return self._finish_early()
except Exception as e:
sickrage.app.log.error(
"{}: Error while loading information from indexer {}. Error: {}".format(self.indexer_id, index_name, e))
......@@ -331,7 +327,7 @@ class QueueItemAdd(ShowQueueItem):
srTraktAPI()["sync/watchlist"].remove(data)
return self._finishEarly()
return self._finish_early()
try:
self.show = TVShow(self.indexer, self.indexer_id, self.lang)
......@@ -381,18 +377,18 @@ class QueueItemAdd(ShowQueueItem):
else:
sickrage.app.alerts.error(
_("Unable to add show due to an error with ") + IndexerApi(self.indexer).name + "")
return self._finishEarly()
return self._finish_early()
except MultipleShowObjectsException:
sickrage.app.log.warning("The show in " + self.showDir + " is already in your show list, skipping")
sickrage.app.alerts.error(_('Show skipped'),
_("The show in ") + self.showDir + _(" is already in your show list"))
return self._finishEarly()
return self._finish_early()
except Exception as e:
sickrage.app.log.error("Error trying to add show: {}".format(e))
sickrage.app.log.debug(traceback.format_exc())
raise self._finishEarly()
raise self._finish_early()
try:
sickrage.app.log.debug("Attempting to retrieve show info from IMDb")
......@@ -405,7 +401,7 @@ class QueueItemAdd(ShowQueueItem):
except Exception as e:
sickrage.app.log.error("Error saving the show to the database: {}".format(e))
sickrage.app.log.debug(traceback.format_exc())
raise self._finishEarly()
raise self._finish_early()
# add it to the show list
if not findCertainShow(self.indexer_id):
......@@ -464,10 +460,10 @@ class QueueItemAdd(ShowQueueItem):
sickrage.app.log.info(
"Finished adding show {} in {}s from show dir: {}".format(self.show_name,
round(time.time() - self.startTime, 2),
round(time.time() - start_time, 2),
self.showDir))
def _finishEarly(self):
def _finish_early(self):
if self.show: sickrage.app.show_queue.removeShow(self.show)
......@@ -479,6 +475,8 @@ class QueueItemRefresh(ShowQueueItem):
self.force = force
def run(self):
start_time = time.time()
sickrage.app.log.info("Performing refresh for show: {}".format(self.show.name))
self.show.refreshDir()
......@@ -494,7 +492,7 @@ class QueueItemRefresh(ShowQueueItem):
self.finish()
sickrage.app.log.info(
"Finished refresh in {}s for show: {}".format(round(time.time() - self.startTime, 2), self.show.name))
"Finished refresh in {}s for show: {}".format(round(time.time() - start_time, 2), self.show.name))
class QueueItemRename(ShowQueueItem):
......@@ -556,6 +554,8 @@ class QueueItemUpdate(ShowQueueItem):
self.force = False
def run(self):
start_time = time.time()
sickrage.app.log.info("Performing updates for show: {}".format(self.show.name))
try:
......@@ -614,7 +614,7 @@ class QueueItemUpdate(ShowQueueItem):
sickrage.app.quicksearch_cache.update_show(self.show.indexerid)
sickrage.app.log.info(
"Finished updates in {}s for show: {}".format(round(time.time() - self.startTime, 2), self.show.name))
"Finished updates in {}s for show: {}".format(round(time.time() - start_time, 2), self.show.name))
# refresh show
sickrage.app.show_queue.refreshShow(self.show, self.force)
......@@ -635,7 +635,7 @@ class QueueItemRemove(ShowQueueItem):
self.full = full
@property
def isLoading(self):
def is_loading(self):
"""
Returns false cause we are removing the show.
"""
......
......@@ -154,10 +154,10 @@ class QueueProgressIndicator():
return len(self.queueItemList)
def numFinished(self):
return len([x for x in self.queueItemList if not x.isInQueue()])
return len([x for x in self.queueItemList if not x.is_in_queue()])
def numRemaining(self):
return len([x for x in self.queueItemList if x.isInQueue()])
return len([x for x in self.queueItemList if x.is_in_queue()])
def nextName(self):
for curItem in [sickrage.app.show_queue.currentItem] + sickrage.app.show_queue.queue:
......
......@@ -1102,29 +1102,29 @@ class Home(WebHandler):
show_message = ''
if sickrage.app.show_queue.isBeingAdded(showObj):
if sickrage.app.show_queue.is_being_added(showObj):
show_message = _('This show is in the process of being downloaded - the info below is incomplete.')
elif sickrage.app.show_queue.isBeingUpdated(showObj):
elif sickrage.app.show_queue.is_being_updated(showObj):
show_message = _('The information on this page is in the process of being updated.')
elif sickrage.app.show_queue.isBeingRefreshed(showObj):
elif sickrage.app.show_queue.is_being_refreshed(showObj):
show_message = _('The episodes below are currently being refreshed from disk')
elif sickrage.app.show_queue.isBeingSubtitled(showObj):
elif sickrage.app.show_queue.is_being_subtitled(showObj):
show_message = _('Currently downloading subtitles for this show')
elif sickrage.app.show_queue.isInRefreshQueue(showObj):
elif sickrage.app.show_queue.is_in_refresh_queue(showObj):
show_message = _('This show is queued to be refreshed.')
elif sickrage.app.show_queue.isInUpdateQueue(showObj):
elif sickrage.app.show_queue.is_in_update_queue(showObj):
show_message = _('This show is queued and awaiting an update.')
elif sickrage.app.show_queue.isInSubtitleQueue(showObj):
elif sickrage.app.show_queue.is_in_subtitle_queue(showObj):
show_message = _('This show is queued and awaiting subtitles download.')
if not sickrage.app.show_queue.isBeingAdded(showObj):
if not sickrage.app.show_queue.isBeingUpdated(showObj):
if not sickrage.app.show_queue.is_being_added(showObj):
if not sickrage.app.show_queue.is_being_updated(showObj):
if showObj.paused:
submenu.append({'title': _('Resume'), 'path': '/home/togglePause?show=%d' % showObj.indexerid,
'icon': 'fas fa-play'})
......@@ -1148,7 +1148,7 @@ class Home(WebHandler):
submenu.append({'title': _('Preview Rename'), 'path': '/home/testRename?show=%d' % showObj.indexerid,
'icon': 'fas fa-tag'})
if sickrage.app.config.use_subtitles and not sickrage.app.show_queue.isBeingSubtitled(
if sickrage.app.config.use_subtitles and not sickrage.app.show_queue.is_being_subtitled(
showObj) and showObj.subtitles:
submenu.append(
{'title': _('Download Subtitles'), 'path': '/home/subtitleShow?show=%d' % showObj.indexerid,
......
......@@ -111,7 +111,7 @@
<div id="${('container', 'container-anime')[curListType == 'Anime' and sickrage.app.config.home_layout == 'poster']}"
class="show-grid clearfix mx-auto d-none">
<div class="posterview">
% for curLoadingShow in sickrage.app.show_queue.loadingShowList:
% for curLoadingShow in sickrage.app.show_queue.loading_show_list:
% if not curLoadingShow.show:
<div class="show-container" data-name="0" data-date="010101" data-network="0"
data-progress="101">
......@@ -296,9 +296,9 @@
</tr>
</thead>
% if sickrage.app.show_queue.loadingShowList:
% if sickrage.app.show_queue.loading_show_list:
<tbody>
% for curLoadingShow in sickrage.app.show_queue.loadingShowList:
% for curLoadingShow in sickrage.app.show_queue.loading_show_list:
% if not curLoadingShow.show or curLoadingShow.show not in sickrage.app.showlist:
<tr>
<td class="table-fit">(${_('loading')})</td>
......
......@@ -86,7 +86,7 @@
<td class="table-fit">
<input type="checkbox" class="showCheck"
id="${curShow.indexerid}"
name="${curShow.indexerid}" ${('disabled', '')[bool(not any([sickrage.app.show_queue.isBeingRenamed(curShow), sickrage.app.show_queue.isInRenameQueue(curShow), sickrage.app.show_queue.isInRefreshQueue(curShow), sickrage.app.show_queue.isBeingUpdated(curShow),sickrage.app.show_queue.isInUpdateQueue(curShow), sickrage.app.show_queue.isBeingRefreshed(curShow), sickrage.app.show_queue.isInRefreshQueue(curShow), sickrage.app.show_queue.isBeingRenamed(curShow), sickrage.app.show_queue.isInRenameQueue(curShow), sickrage.app.show_queue.isBeingSubtitled(curShow), sickrage.app.show_queue.isInSubtitleQueue(curShow)]))]}/>
name="${curShow.indexerid}" ${('disabled', '')[bool(not any([sickrage.app.show_queue.is_being_renamed(curShow), sickrage.app.show_queue.is_in_rename_queue(curShow), sickrage.app.show_queue.is_in_refresh_queue(curShow), sickrage.app.show_queue.is_being_updated(curShow),sickrage.app.show_queue.is_in_update_queue(curShow), sickrage.app.show_queue.is_being_refreshed(curShow), sickrage.app.show_queue.is_in_refresh_queue(curShow), sickrage.app.show_queue.is_being_renamed(curShow), sickrage.app.show_queue.is_in_rename_queue(curShow), sickrage.app.show_queue.is_being_subtitled(curShow), sickrage.app.show_queue.is_in_subtitle_queue(curShow)]))]}/>
</td>
<td class="tvShow">
<a href="${srWebRoot}/home/displayShow?show=${curShow.indexerid}">${curShow.name}</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment