From a1da7df12ee1f5fc84205c6f08861c448596701b Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 7 Jun 2014 15:35:16 -0700 Subject: [PATCH] Fixes for DB issues --- gui/slick/interfaces/default/config.tmpl | 13 ++++++ sickbeard/providers/btn.py | 4 +- sickbeard/providers/hdbits.py | 4 +- sickbeard/providers/hdtorrents.py | 4 +- sickbeard/providers/iptorrents.py | 4 +- sickbeard/providers/kat.py | 4 +- sickbeard/providers/newznab.py | 4 +- sickbeard/providers/nextgen.py | 4 +- sickbeard/providers/publichd.py | 4 +- sickbeard/providers/scc.py | 4 +- sickbeard/providers/speedcd.py | 4 +- sickbeard/providers/thepiratebay.py | 4 +- sickbeard/providers/torrentday.py | 4 +- sickbeard/providers/torrentleech.py | 4 +- sickbeard/scene_numbering.py | 3 +- sickbeard/tv.py | 2 +- sickbeard/tvcache.py | 53 +++++++++++------------- 17 files changed, 67 insertions(+), 56 deletions(-) diff --git a/gui/slick/interfaces/default/config.tmpl b/gui/slick/interfaces/default/config.tmpl index 7b980366..889c293f 100644 --- a/gui/slick/interfaces/default/config.tmpl +++ b/gui/slick/interfaces/default/config.tmpl @@ -1,4 +1,5 @@ #import sickbeard +#import psutil #from sickbeard import db #import os.path #set global $title="Configuration" @@ -14,6 +15,17 @@

$title

#end if +#set cpu_usage = $psutil.cpu_percent() +#set ram = $psutil.phymem_usage() +#set ram_total = $ram.total / 2**20 +#set ram_used = $ram.used / 2**20 +#set ram_free = $ram.free / 2**20 +#set ram_percent_used = $ram.percent +#set disk = $psutil.disk_usage('/') +#set disk_total = $disk.total / 2**30 +#set disk_used = $disk.used / 2**30 +#set disk_free = $disk.free / 2**30 +#set disk_percent_used = $disk.percent
@@ -25,6 +37,7 @@ #end if You are using BETA software + diff --git a/sickbeard/providers/btn.py b/sickbeard/providers/btn.py index 1445eac8..0a8afa13 100644 --- a/sickbeard/providers/btn.py +++ b/sickbeard/providers/btn.py @@ -343,8 +343,8 @@ class BTNCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) else: raise AuthException( diff --git a/sickbeard/providers/hdbits.py b/sickbeard/providers/hdbits.py index ab5829c1..e5396785 100644 --- a/sickbeard/providers/hdbits.py +++ b/sickbeard/providers/hdbits.py @@ -255,8 +255,8 @@ class HDBitsCache(tvcache.TVCache): ql.append(ci) if ql: - myDB = self._getDB() - myDB.mass_action(ql) + with self._getDB() as myDB: + myDB.mass_action(ql) else: raise exceptions.AuthException( diff --git a/sickbeard/providers/hdtorrents.py b/sickbeard/providers/hdtorrents.py index 48371139..a4dad9f6 100644 --- a/sickbeard/providers/hdtorrents.py +++ b/sickbeard/providers/hdtorrents.py @@ -377,8 +377,8 @@ class HDTorrentsCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/iptorrents.py b/sickbeard/providers/iptorrents.py index 8df27e2f..76bc911c 100644 --- a/sickbeard/providers/iptorrents.py +++ b/sickbeard/providers/iptorrents.py @@ -318,8 +318,8 @@ class IPTorrentsCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py index ec45b57b..96307336 100644 --- a/sickbeard/providers/kat.py +++ b/sickbeard/providers/kat.py @@ -455,8 +455,8 @@ class KATCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index 7affc1a7..dbc9cb1b 100644 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -342,8 +342,8 @@ class NewznabCache(tvcache.TVCache): ql.append(ci) if ql: - myDB = self._getDB() - myDB.mass_action(ql) + with self._getDB() as myDB: + myDB.mass_action(ql) else: raise AuthException( diff --git a/sickbeard/providers/nextgen.py b/sickbeard/providers/nextgen.py index 7b2e2571..4f450425 100644 --- a/sickbeard/providers/nextgen.py +++ b/sickbeard/providers/nextgen.py @@ -367,8 +367,8 @@ class NextGenCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/publichd.py b/sickbeard/providers/publichd.py index 5b4a2718..901f006b 100644 --- a/sickbeard/providers/publichd.py +++ b/sickbeard/providers/publichd.py @@ -340,8 +340,8 @@ class PublicHDCache(tvcache.TVCache): ql.append(ci) if ql: - myDB = self._getDB() - myDB.mass_action(ql) + with self._getDB() as myDB: + myDB.mass_action(ql) def _parseItem(self, item): diff --git a/sickbeard/providers/scc.py b/sickbeard/providers/scc.py index 5f233bb8..4d2d8d42 100644 --- a/sickbeard/providers/scc.py +++ b/sickbeard/providers/scc.py @@ -362,8 +362,8 @@ class SCCCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/speedcd.py b/sickbeard/providers/speedcd.py index 889ef28b..e795b0bc 100644 --- a/sickbeard/providers/speedcd.py +++ b/sickbeard/providers/speedcd.py @@ -302,8 +302,8 @@ class SpeedCDCache(tvcache.TVCache): ql.append(ci) if ql: - myDB = self._getDB() - myDB.mass_action(ql) + with self._getDB() as myDB: + myDB.mass_action(ql) def _parseItem(self, item): diff --git a/sickbeard/providers/thepiratebay.py b/sickbeard/providers/thepiratebay.py index b29784ba..dbef307d 100644 --- a/sickbeard/providers/thepiratebay.py +++ b/sickbeard/providers/thepiratebay.py @@ -435,8 +435,8 @@ class ThePirateBayCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/torrentday.py b/sickbeard/providers/torrentday.py index f84ce223..fc621878 100644 --- a/sickbeard/providers/torrentday.py +++ b/sickbeard/providers/torrentday.py @@ -326,8 +326,8 @@ class TorrentDayCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/torrentleech.py b/sickbeard/providers/torrentleech.py index 02d3cb35..40795c22 100644 --- a/sickbeard/providers/torrentleech.py +++ b/sickbeard/providers/torrentleech.py @@ -321,8 +321,8 @@ class TorrentLeechCache(tvcache.TVCache): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/scene_numbering.py b/sickbeard/scene_numbering.py index 9f12de06..7076c40a 100644 --- a/sickbeard/scene_numbering.py +++ b/sickbeard/scene_numbering.py @@ -693,4 +693,5 @@ def fix_xem_numbering(indexer_id, indexer): update_scene_absolute_number = False if ql: - myDB.mass_action(ql) \ No newline at end of file + with db.DBConnection() as myDB: + myDB.mass_action(ql) \ No newline at end of file diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 18502fea..7024a5e4 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -203,7 +203,7 @@ class TVShow(object): if self.is_anime and absolute_number and not season and not episode: with db.DBConnection() as myDB: sql = "SELECT * FROM tv_episodes WHERE showid = ? and absolute_number = ? and season != 0" - sqlResults = myDB.select(sql, [self.indexerid, absolute_number]) + sqlResults = myDB.select(sql, [self.indexerid, absolute_number]) if len(sqlResults) == 1: episode = int(sqlResults[0]["episode"]) diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index ac98d667..055bd961 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -82,11 +82,10 @@ class TVCache(): if not self.shouldClearCache(): return - myDB = self._getDB() - curDate = datetime.date.today() - datetime.timedelta(weeks=1) - myDB.action("DELETE FROM [" + self.providerID + "] WHERE time < ?", [int(time.mktime(curDate.timetuple()))]) + with self._getDB() as myDB: + myDB.action("DELETE FROM [" + self.providerID + "] WHERE time < ?", [int(time.mktime(curDate.timetuple()))]) def _getRSSData(self): @@ -127,8 +126,8 @@ class TVCache(): cl.append(ci) if cl: - myDB = self._getDB() - myDB.mass_action(cl) + with self._getDB() as myDB: + myDB.mass_action(cl) else: raise AuthException( @@ -194,8 +193,8 @@ class TVCache(): def _getLastUpdate(self): - myDB = self._getDB() - sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID]) + with self._getDB() as myDB: + sqlResults = myDB.select("SELECT time FROM lastUpdate WHERE provider = ?", [self.providerID]) if sqlResults: lastTime = int(sqlResults[0]["time"]) @@ -207,8 +206,8 @@ class TVCache(): return datetime.datetime.fromtimestamp(lastTime) def _getLastSearch(self): - myDB = self._getDB() - sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID]) + with self._getDB() as myDB: + sqlResults = myDB.select("SELECT time FROM lastSearch WHERE provider = ?", [self.providerID]) if sqlResults: lastTime = int(sqlResults[0]["time"]) @@ -224,19 +223,19 @@ class TVCache(): if not toDate: toDate = datetime.datetime.today() - myDB = self._getDB() - myDB.upsert("lastUpdate", - {'time': int(time.mktime(toDate.timetuple()))}, - {'provider': self.providerID}) + with self._getDB() as myDB: + myDB.upsert("lastUpdate", + {'time': int(time.mktime(toDate.timetuple()))}, + {'provider': self.providerID}) def setLastSearch(self, toDate=None): if not toDate: toDate = datetime.datetime.today() - myDB = self._getDB() - myDB.upsert("lastSearch", - {'time': int(time.mktime(toDate.timetuple()))}, - {'provider': self.providerID}) + with self._getDB() as myDB: + myDB.upsert("lastSearch", + {'time': int(time.mktime(toDate.timetuple()))}, + {'provider': self.providerID}) lastUpdate = property(_getLastUpdate) lastSearch = property(_getLastSearch) @@ -316,25 +315,23 @@ class TVCache(): return neededEps def listPropers(self, date=None, delimiter="."): - myDB = self._getDB() + with self._getDB() as myDB: + sql = "SELECT * FROM [" + self.providerID + "] WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%'" - sql = "SELECT * FROM [" + self.providerID + "] WHERE name LIKE '%.PROPER.%' OR name LIKE '%.REPACK.%'" + if date != None: + sql += " AND time >= " + str(int(time.mktime(date.timetuple()))) - if date != None: - sql += " AND time >= " + str(int(time.mktime(date.timetuple()))) - - return filter(lambda x: x['indexerid'] != 0, myDB.select(sql)) + return filter(lambda x: x['indexerid'] != 0, myDB.select(sql)) def findNeededEpisodes(self, episodes, manualSearch=False): neededEps = {} - cacheDB = self._getDB() - for epObj in episodes: - sqlResults = cacheDB.select( - "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", - [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]) + with self._getDB() as myDB: + sqlResults = myDB.select( + "SELECT * FROM [" + self.providerID + "] WHERE indexerid = ? AND season = ? AND episodes LIKE ?", + [epObj.show.indexerid, epObj.season, "%|" + str(epObj.episode) + "|%"]) # for each cache entry for curResult in sqlResults:
Memory Used: $ram_percent_used
SR Config file: $sickbeard.CONFIG_FILE
SR Database file: $db.dbFilename()
SR Cache Dir: $sickbeard.CACHE_DIR