From 75f69396d4ce75681e9f4cfe5e8b368ac539dabc Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 30 Jun 2014 08:57:32 -0700 Subject: [PATCH] Reverted some changes. --- SickBeard.py | 37 ++++++++++++++++------------- sickbeard/dailysearcher.py | 12 ++++------ sickbeard/db.py | 16 +++++-------- sickbeard/network_timezones.py | 2 +- sickbeard/postProcessor.py | 4 ++-- sickbeard/providers/btn.py | 1 - sickbeard/providers/hdbits.py | 2 +- sickbeard/providers/hdtorrents.py | 2 +- sickbeard/providers/iptorrents.py | 2 +- sickbeard/providers/kat.py | 2 +- sickbeard/providers/newznab.py | 2 +- sickbeard/providers/nextgen.py | 2 +- sickbeard/providers/publichd.py | 2 +- sickbeard/providers/scc.py | 2 +- sickbeard/providers/speedcd.py | 2 +- sickbeard/providers/thepiratebay.py | 2 +- sickbeard/providers/torrentday.py | 2 +- sickbeard/providers/torrentleech.py | 2 +- sickbeard/providers/womble.py | 1 - sickbeard/scene_numbering.py | 3 +-- sickbeard/search.py | 2 +- sickbeard/tv.py | 12 +++++----- sickbeard/tvcache.py | 25 +++++++++---------- sickbeard/webapi.py | 2 +- sickbeard/webserve.py | 2 +- sickbeard/webserveInit.py | 1 - 26 files changed, 68 insertions(+), 76 deletions(-) diff --git a/SickBeard.py b/SickBeard.py index 933bcb1c..a5c476fd 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -19,6 +19,7 @@ # Check needed software dependencies to nudge users to fix their setup from __future__ import with_statement +import functools import sys import shutil @@ -377,31 +378,35 @@ def main(): sickbeard.launchBrowser(startPort) sys.exit() - def startup(): - # Build from the DB to start with - loadShowsFromDB() + # Build from the DB to start with + loadShowsFromDB() - # Fire up all our threads - sickbeard.start() + # Fire up all our threads + sickbeard.start() - # Launch browser if we're supposed to - if sickbeard.LAUNCH_BROWSER and not noLaunch and not sickbeard.DAEMON and not sickbeard.restarted: - sickbeard.launchBrowser(startPort) + # Launch browser if we're supposed to + if sickbeard.LAUNCH_BROWSER and not noLaunch: + sickbeard.launchBrowser(startPort) - # Start an update if we're supposed to - if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START: - sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable + # Start an update if we're supposed to + if forceUpdate or sickbeard.UPDATE_SHOWS_ON_START: + sickbeard.showUpdateScheduler.action.run(force=True) # @UndefinedVariable - # If we restarted then unset the restarted flag - if sickbeard.restarted: - sickbeard.restarted = False + # If we restarted then unset the restarted flag + if sickbeard.restarted: + sickbeard.restarted = False - # create ioloop + # IOLoop io_loop = IOLoop.current() - io_loop.add_timeout(datetime.timedelta(seconds=5), startup) + # Open browser window + if sickbeard.LAUNCH_BROWSER and not (noLaunch or sickbeard.DAEMON or sickbeard.restarted): + io_loop.add_timeout(datetime.timedelta(seconds=5), functools.partial(sickbeard.launchBrowser, startPort)) + # Start web server io_loop.start() + + # Save and restart/shutdown sickbeard.saveAndShutdown() if __name__ == "__main__": diff --git a/sickbeard/dailysearcher.py b/sickbeard/dailysearcher.py index a6d97f97..967d3a47 100644 --- a/sickbeard/dailysearcher.py +++ b/sickbeard/dailysearcher.py @@ -85,10 +85,10 @@ class DailySearcher(): with ep.lock: if ep.show.paused: ep.status = common.SKIPPED - else: - if ep.status == common.UNAIRED: - logger.log(u"New episode " + ep.prettyName() + " airs today, setting status to WANTED") - ep.status = common.WANTED + + if ep.status == common.UNAIRED: + logger.log(u"New episode " + ep.prettyName() + " airs today, setting status to WANTED") + ep.status = common.WANTED if ep.status == common.WANTED: if show not in todaysEps: @@ -101,7 +101,7 @@ class DailySearcher(): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + if len(todaysEps): for show in todaysEps: @@ -115,6 +115,4 @@ class DailySearcher(): else: logger.log(u"Could not find any needed episodes to search for ...") - del todaysEps - self.amActive = False \ No newline at end of file diff --git a/sickbeard/db.py b/sickbeard/db.py index b25e107d..92f6d917 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -111,7 +111,7 @@ class DBConnection(object): if self.hasTable('db_version'): result = self.select("SELECT db_version FROM db_version") except: - pass + return 0 if result: return int(result[0]["db_version"]) @@ -153,7 +153,7 @@ class DBConnection(object): if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: logger.log(u"DB error: " + ex(e), logger.WARNING) attempt += 1 - time.sleep(0.02) + time.sleep(1) else: logger.log(u"DB error: " + ex(e), logger.ERROR) raise @@ -164,7 +164,7 @@ class DBConnection(object): logger.log(u"Fatal error executing query: " + ex(e), logger.ERROR) raise - return sqlResult + return sqlResult def action(self, query, args=None, fetchall=False, fetchone=False): @@ -191,7 +191,7 @@ class DBConnection(object): if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: logger.log(u"DB error: " + ex(e), logger.WARNING) attempt += 1 - time.sleep(0.02) + time.sleep(1) else: logger.log(u"DB error: " + ex(e), logger.ERROR) raise @@ -199,7 +199,7 @@ class DBConnection(object): logger.log(u"Fatal error executing query: " + ex(e), logger.ERROR) raise - return sqlResult + return sqlResult def select(self, query, args=None): @@ -342,11 +342,7 @@ class SchemaUpgrade(object): self.connection.action("UPDATE %s SET %s = ?" % (table, column), (default,)) def checkDBVersion(self): - result = self.connection.select("SELECT db_version FROM db_version") - if result: - return int(result[0]["db_version"]) - else: - return 0 + return self.connection.checkDBVersion() def incDBVersion(self): new_version = self.checkDBVersion() + 1 diff --git a/sickbeard/network_timezones.py b/sickbeard/network_timezones.py index 64cf37ad..28520878 100644 --- a/sickbeard/network_timezones.py +++ b/sickbeard/network_timezones.py @@ -192,7 +192,7 @@ def update_network_dict(): if ql: myDB.mass_action(ql) load_network_dict() - del ql + # load network timezones from db into dict def load_network_dict(): diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 233c2fab..57f352c1 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -965,7 +965,7 @@ class PostProcessor(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + # find the destination folder try: @@ -1043,7 +1043,7 @@ class PostProcessor(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + # log it to history history.logDownload(ep_obj, self.file_path, new_ep_quality, self.release_group) diff --git a/sickbeard/providers/btn.py b/sickbeard/providers/btn.py index 0b1518b5..71c69c48 100644 --- a/sickbeard/providers/btn.py +++ b/sickbeard/providers/btn.py @@ -346,7 +346,6 @@ class BTNCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl else: raise AuthException( diff --git a/sickbeard/providers/hdbits.py b/sickbeard/providers/hdbits.py index ee1ae26d..5737114a 100644 --- a/sickbeard/providers/hdbits.py +++ b/sickbeard/providers/hdbits.py @@ -257,7 +257,7 @@ class HDBitsCache(tvcache.TVCache): if ql: myDB = self._getDB() myDB.mass_action(ql) - del ql + else: raise exceptions.AuthException( diff --git a/sickbeard/providers/hdtorrents.py b/sickbeard/providers/hdtorrents.py index b506d794..d0b3f5a4 100644 --- a/sickbeard/providers/hdtorrents.py +++ b/sickbeard/providers/hdtorrents.py @@ -379,7 +379,7 @@ class HDTorrentsCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/iptorrents.py b/sickbeard/providers/iptorrents.py index 76a80173..7d78df12 100644 --- a/sickbeard/providers/iptorrents.py +++ b/sickbeard/providers/iptorrents.py @@ -320,7 +320,7 @@ class IPTorrentsCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py index dbffb658..d2f196ac 100644 --- a/sickbeard/providers/kat.py +++ b/sickbeard/providers/kat.py @@ -457,7 +457,7 @@ class KATCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index 59f0ca5a..6ff1f239 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -344,7 +344,7 @@ class NewznabCache(tvcache.TVCache): if ql: myDB = self._getDB() myDB.mass_action(ql) - del ql + else: raise AuthException( diff --git a/sickbeard/providers/nextgen.py b/sickbeard/providers/nextgen.py index 91bc9dc3..8e1685c4 100644 --- a/sickbeard/providers/nextgen.py +++ b/sickbeard/providers/nextgen.py @@ -369,7 +369,7 @@ class NextGenCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/publichd.py b/sickbeard/providers/publichd.py index 3fae3429..13a3ea2d 100644 --- a/sickbeard/providers/publichd.py +++ b/sickbeard/providers/publichd.py @@ -342,7 +342,7 @@ class PublicHDCache(tvcache.TVCache): if ql: myDB = self._getDB() myDB.mass_action(ql) - del ql + def _parseItem(self, item): diff --git a/sickbeard/providers/scc.py b/sickbeard/providers/scc.py index 71eb2155..4ec68eef 100644 --- a/sickbeard/providers/scc.py +++ b/sickbeard/providers/scc.py @@ -364,7 +364,7 @@ class SCCCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/speedcd.py b/sickbeard/providers/speedcd.py index e238a8ea..690e11ac 100644 --- a/sickbeard/providers/speedcd.py +++ b/sickbeard/providers/speedcd.py @@ -304,7 +304,7 @@ class SpeedCDCache(tvcache.TVCache): if ql: myDB = self._getDB() myDB.mass_action(ql) - del ql + def _parseItem(self, item): diff --git a/sickbeard/providers/thepiratebay.py b/sickbeard/providers/thepiratebay.py index 336aedf8..54a49817 100644 --- a/sickbeard/providers/thepiratebay.py +++ b/sickbeard/providers/thepiratebay.py @@ -437,7 +437,7 @@ class ThePirateBayCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/torrentday.py b/sickbeard/providers/torrentday.py index 6e4f07be..9fadfab1 100644 --- a/sickbeard/providers/torrentday.py +++ b/sickbeard/providers/torrentday.py @@ -328,7 +328,7 @@ class TorrentDayCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/torrentleech.py b/sickbeard/providers/torrentleech.py index d5ae7ab3..833749be 100644 --- a/sickbeard/providers/torrentleech.py +++ b/sickbeard/providers/torrentleech.py @@ -323,7 +323,7 @@ class TorrentLeechCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl + def _parseItem(self, item): diff --git a/sickbeard/providers/womble.py b/sickbeard/providers/womble.py index 173b4add..c14dfc7a 100644 --- a/sickbeard/providers/womble.py +++ b/sickbeard/providers/womble.py @@ -70,7 +70,6 @@ class WombleCache(tvcache.TVCache): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl # set last updated if data: diff --git a/sickbeard/scene_numbering.py b/sickbeard/scene_numbering.py index 60774ce6..e42ddc7c 100644 --- a/sickbeard/scene_numbering.py +++ b/sickbeard/scene_numbering.py @@ -528,7 +528,7 @@ def xem_refresh(indexer_id, indexer, force=False): if ql: myDB = db.DBConnection() myDB.mass_action(ql) - del ql + def fix_xem_numbering(indexer_id, indexer): """ @@ -692,4 +692,3 @@ def fix_xem_numbering(indexer_id, indexer): if ql: myDB = db.DBConnection() myDB.mass_action(ql) - del ql \ No newline at end of file diff --git a/sickbeard/search.py b/sickbeard/search.py index 6bdc06b5..a8450cfd 100644 --- a/sickbeard/search.py +++ b/sickbeard/search.py @@ -175,7 +175,7 @@ def snatchEpisode(result, endStatus=SNATCHED): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + return True diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 28a6c521..f06d75dd 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -456,7 +456,7 @@ class TVShow(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + def loadEpisodesFromDB(self): @@ -578,7 +578,7 @@ class TVShow(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + # Done updating save last update date self.last_update_indexer = datetime.date.today().toordinal() @@ -749,7 +749,7 @@ class TVShow(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + # creating metafiles on the root should be good enough if sickbeard.USE_FAILED_DOWNLOADS and rootEp is not None: @@ -1005,7 +1005,7 @@ class TVShow(object): myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + # remove self from show list sickbeard.showList = [x for x in sickbeard.showList if int(x.indexerid) != self.indexerid] @@ -1080,7 +1080,7 @@ class TVShow(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + def airdateModifyStamp(self, ep_obj): """ @@ -2420,4 +2420,4 @@ class TVEpisode(object): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index 74477c2f..8dfeb7e8 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -37,6 +37,7 @@ from sickbeard.rssfeeds import RSSFeeds cache_lock = threading.Lock() + class CacheDBConnection(db.DBConnection): def __init__(self, providerName): db.DBConnection.__init__(self, "cache.db") @@ -67,6 +68,7 @@ class CacheDBConnection(db.DBConnection): if str(e) != "table lastUpdate already exists": raise + class TVCache(): def __init__(self, provider): @@ -75,11 +77,12 @@ class TVCache(): self.minTime = 10 def _getDB(self): - return CacheDBConnection(self.providerID) def _clearCache(self): if self.shouldClearCache(): + logger.log(u"Clearing " + self.provider.name + " cache") + curDate = datetime.date.today() - datetime.timedelta(weeks=1) myDB = self._getDB() @@ -103,14 +106,9 @@ class TVCache(): def updateCache(self): - # delete anything older then 7 days - logger.log(u"Clearing " + self.provider.name + " cache") - self._clearCache() + if self.shouldUpdate() and self._checkAuth(None): + self._clearCache() - if not self.shouldUpdate(): - return - - if self._checkAuth(None): data = self._getRSSData() # as long as the http request worked we count this as an update @@ -129,7 +127,6 @@ class TVCache(): if cl: myDB = self._getDB() myDB.mass_action(cl) - del cl else: raise AuthException( u"Your authentication credentials for " + self.provider.name + " are incorrect, check your config") @@ -219,10 +216,10 @@ class TVCache(): def shouldUpdate(self): # if we've updated recently then skip the update - # if datetime.datetime.today() - self.lastUpdate < datetime.timedelta(minutes=self.minTime): - # logger.log(u"Last update was too soon, using old cache: today()-" + str(self.lastUpdate) + "<" + str( - # datetime.timedelta(minutes=self.minTime)), logger.DEBUG) - # return False + if datetime.datetime.today() - self.lastUpdate < datetime.timedelta(minutes=self.minTime): + logger.log(u"Last update was too soon, using old cache: today()-" + str(self.lastUpdate) + "<" + str( + datetime.timedelta(minutes=self.minTime)), logger.DEBUG) + return False return True @@ -230,7 +227,7 @@ class TVCache(): # if daily search hasn't used our previous results yet then don't clear the cache if self.lastUpdate > self.lastSearch: logger.log( - u"Daily search has not yet searched our last cache results, skipping clearig cache ...", logger.DEBUG) + u"Daily search has not yet used our last cache results, not clearing cache ...", logger.DEBUG) return False return True diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index f294981f..ffa7701c 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -1007,7 +1007,7 @@ class CMD_EpisodeSetStatus(ApiCall): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + extra_msg = "" if start_backlog: diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 755edd15..c55dbdc5 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -3998,7 +3998,7 @@ class Home(MainHandler): if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) - del sql_l + if int(status) == WANTED: msg = "Backlog was automatically started for the following seasons of " + showObj.name + ":
" diff --git a/sickbeard/webserveInit.py b/sickbeard/webserveInit.py index 7eb4906d..a6416e00 100644 --- a/sickbeard/webserveInit.py +++ b/sickbeard/webserveInit.py @@ -1,6 +1,5 @@ import os import traceback -import time import sickbeard import webserve import webapi