From 75f59d717e4c7b7ae166d36c4e443d350166188d Mon Sep 17 00:00:00 2001 From: Prinz23 Date: Tue, 5 Sep 2017 21:24:26 +0100 Subject: [PATCH] Change add switchIgnoreWarning and log_num_not_found_shows to PageTemplate. --- .../default/manage_showProcesses.tmpl | 4 ++ sickbeard/tv.py | 46 ++++++++++++------- sickbeard/webserve.py | 22 +++++++-- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/gui/slick/interfaces/default/manage_showProcesses.tmpl b/gui/slick/interfaces/default/manage_showProcesses.tmpl index 40134ea2..ef4fe61e 100644 --- a/gui/slick/interfaces/default/manage_showProcesses.tmpl +++ b/gui/slick/interfaces/default/manage_showProcesses.tmpl @@ -35,6 +35,7 @@ Show name Last found + No warn icon #set $row = 0 #for $cur_show in $NotFoundShows: @@ -43,6 +44,9 @@ $cur_show['show_name'] $cur_show['last_success'] + + + #end for diff --git a/sickbeard/tv.py b/sickbeard/tv.py index bdea35fc..761dd95d 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -117,7 +117,7 @@ class TVShow(object): self._overview = '' self._tag = '' self._mapped_ids = {} - self._not_found_count = -1 + self._not_found_count = None self._last_found_on_indexer = -1 self.dirty = True @@ -166,7 +166,7 @@ class TVShow(object): tag = property(lambda self: self._tag, dirty_setter('_tag')) def _helper_load_failed_db(self): - if self._not_found_count == -1 or self._last_found_on_indexer == -1: + if None is self._not_found_count or self._last_found_on_indexer == -1: myDB = db.DBConnection() results = myDB.select('SELECT fail_count, last_success FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', [self.indexer, self.indexerid]) @@ -184,7 +184,22 @@ class TVShow(object): @not_found_count.setter def not_found_count(self, v): - self._not_found_count = v + if isinstance(v, (int, long)) and v != self._not_found_count: + self._last_found_on_indexer = self.last_found_on_indexer + myDB = db.DBConnection() + # noinspection PyUnresolvedReferences + last_check = sbdatetime.now().totimestamp(default=0) + # in case of flag change (+/-) don't change last_check date + if abs(v) == abs(self._not_found_count): + results = myDB.select('SELECT last_check FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', + [self.indexer, self.indexerid]) + if results: + last_check = helpers.tryInt(results[0]['last_check']) + myDB.upsert('tv_shows_not_found', + {'fail_count': v, 'last_check': last_check, + 'last_success': self._last_found_on_indexer}, + {'indexer': self.indexer, 'indexer_id': self.indexerid}) + self._not_found_count = v @property def last_found_on_indexer(self): @@ -193,24 +208,20 @@ class TVShow(object): def inc_not_found_count(self): myDB = db.DBConnection() - results = myDB.select('SELECT fail_count, last_check, last_success FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', + results = myDB.select('SELECT last_check FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', [self.indexer, self.indexerid]) - days = (show_not_found_retry_days - 1, 0)[self.not_found_count <= concurrent_show_not_found_days] - if not results or datetime.datetime.fromtimestamp(helpers.tryInt(results[0]['last_check'])) + datetime.timedelta(days=days, hours=18) < datetime.datetime.now(): - if self.not_found_count <= 0: - last_success = self.last_update_indexer - else: - last_success = helpers.tryInt(results[0]['last_success'], self.last_update_indexer) - self._last_found_on_indexer = last_success - self.not_found_count += 1 - myDB.upsert('tv_shows_not_found', {'fail_count': self.not_found_count, 'last_check': sbdatetime.now().totimestamp(default=0), 'last_success': last_success}, - {'indexer': self.indexer, 'indexer_id': self.indexerid}) + days = (show_not_found_retry_days - 1, 0)[abs(self.not_found_count) <= concurrent_show_not_found_days] + if not results or datetime.datetime.fromtimestamp(helpers.tryInt(results[0]['last_check'])) + \ + datetime.timedelta(days=days, hours=18) < datetime.datetime.now(): + self.not_found_count += (-1, 1)[0 <= self.not_found_count] def reset_not_found_count(self): - if self.not_found_count > 0: + if 0 != self.not_found_count: self._not_found_count = 0 + self._last_found_on_indexer = 0 myDB = db.DBConnection() - myDB.action('DELETE FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', [self.indexer, self.indexerid]) + myDB.action('DELETE FROM tv_shows_not_found WHERE indexer = ? AND indexer_id = ?', + [self.indexer, self.indexerid]) @property def ids(self): @@ -382,7 +393,8 @@ class TVShow(object): last_update_indexer = datetime.date.fromordinal(self.last_update_indexer) # if show was not found for 1 week, only retry to update once a week - if concurrent_show_not_found_days < self.not_found_count and (update_date - last_update_indexer) < datetime.timedelta(days=show_not_found_retry_days): + if (concurrent_show_not_found_days < abs(self.not_found_count)) \ + and (update_date - last_update_indexer) < datetime.timedelta(days=show_not_found_retry_days): return False myDB = db.DBConnection() diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index de7537d5..8feb3093 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -96,6 +96,7 @@ class PageTemplate(Template): self.sbThemeName = sickbeard.THEME_NAME self.log_num_errors = len(classes.ErrorViewer.errors) + self.log_num_not_found_shows = len([x for x in sickbeard.showList if 0 < x.not_found_count]) self.sbPID = str(sickbeard.PID) self.menu = [ {'title': 'Home', 'key': 'home'}, @@ -1319,7 +1320,7 @@ class Home(MainHandler): elif sickbeard.showQueueScheduler.action.isInSubtitleQueue(showObj): # @UndefinedVariable show_message = 'This show is queued and awaiting subtitles download.' - if 0 < showObj.not_found_count: + if 0 != showObj.not_found_count: last_found = ('', ' since %s' % sbdatetime.sbdatetime.fromordinal( showObj.last_found_on_indexer).sbfdate())[1 < showObj.last_found_on_indexer] show_message = ( @@ -1784,12 +1785,12 @@ class Home(MainHandler): self.fanart_tmpl(t) t.num_ratings = len(sickbeard.FANART_RATINGS.get(str(t.show.indexerid), {})) - t.unlock_master_id = 0 < showObj.not_found_count + t.unlock_master_id = 0 != showObj.not_found_count t.showname_enc = urllib.quote_plus(showObj.name.encode('utf-8')) show_message = '' - if 0 < showObj.not_found_count: + if 0 != showObj.not_found_count: # noinspection PyUnresolvedReferences last_found = ('', ' since %s' % sbdatetime.sbdatetime.fromordinal( showObj.last_found_on_indexer).sbfdate())[1 < showObj.last_found_on_indexer] @@ -4614,10 +4615,11 @@ class showProcesses(Manage): t.ShowUpdateRunning = sickbeard.showQueueScheduler.action.isShowUpdateRunning() or sickbeard.showUpdateScheduler.action.amActive myDb = db.DBConnection(row_type='dict') - sql_results = myDb.select('SELECT n.indexer, n.indexer_id, n.last_success, s.show_name FROM tv_shows_not_found as n INNER JOIN tv_shows as s ON (n.indexer == s.indexer AND n.indexer_id == s.indexer_id)') + sql_results = myDb.select('SELECT n.indexer, n.indexer_id, n.last_success, n.fail_count, s.show_name FROM tv_shows_not_found as n INNER JOIN tv_shows as s ON (n.indexer == s.indexer AND n.indexer_id == s.indexer_id)') for s in sql_results: date = helpers.tryInt(s['last_success']) s['last_success'] = ('never', sbdatetime.sbdatetime.fromordinal(date).sbfdate())[date > 1] + s['ignore_warning'] = 0 > s['fail_count'] defunct_indexer = [i for i in sickbeard.indexerApi().all_indexers if sickbeard.indexerApi(i).config.get('defunct')] sql_r = None if defunct_indexer: @@ -4639,6 +4641,18 @@ class showProcesses(Manage): time.sleep(5) self.redirect('/manage/showProcesses/') + def switchIgnoreWarning(self, indexer=None, indexer_id=None, *args, **kwargs): + indexer = helpers.tryInt(indexer) + indexer_id = helpers.tryInt(indexer_id) + showObj = helpers.find_show_by_id(sickbeard.showList, {indexer: indexer_id}) + + if not showObj: + return json.dumps({'indexer': indexer, 'indexer_id': indexer_id, 'error': 'Show not found'}) + + showObj.not_found_count *= -1 + + return json.dumps({'indexer': indexer, 'indexer_id': indexer_id, 'ignore_warning': 0 > showObj.not_found_count}) + class History(MainHandler): def index(self, limit=100):