From 997896a540a784766b8b6375b9549b2044a9007a Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 30 May 2014 04:42:31 -0700 Subject: [PATCH] Fix for transactionals and None Types in sql lists --- sickbeard/dailysearcher.py | 2 +- sickbeard/db.py | 3 +++ sickbeard/network_timezones.py | 2 +- sickbeard/postProcessor.py | 4 ++-- sickbeard/providers/btn.py | 5 +++-- sickbeard/providers/hdbits.py | 5 +++-- sickbeard/providers/hdtorrents.py | 5 +++-- sickbeard/providers/iptorrents.py | 5 +++-- sickbeard/providers/kat.py | 5 +++-- sickbeard/providers/newznab.py | 5 +++-- sickbeard/providers/nextgen.py | 5 +++-- sickbeard/providers/publichd.py | 5 +++-- sickbeard/providers/scc.py | 5 +++-- sickbeard/providers/speedcd.py | 5 +++-- sickbeard/providers/thepiratebay.py | 5 +++-- sickbeard/providers/torrentday.py | 5 +++-- sickbeard/providers/torrentleech.py | 5 +++-- sickbeard/search.py | 2 +- sickbeard/tv.py | 10 +++++----- sickbeard/tvcache.py | 5 +++-- sickbeard/webapi.py | 2 +- sickbeard/webserve.py | 2 +- 22 files changed, 57 insertions(+), 40 deletions(-) diff --git a/sickbeard/dailysearcher.py b/sickbeard/dailysearcher.py index f7c9672b..d0ca71bd 100644 --- a/sickbeard/dailysearcher.py +++ b/sickbeard/dailysearcher.py @@ -81,7 +81,7 @@ class DailySearcher(): sql_l.append(ep.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) diff --git a/sickbeard/db.py b/sickbeard/db.py index c84a5ee3..a324a745 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -30,6 +30,7 @@ from sickbeard import encodingKludge as ek from sickbeard import logger from sickbeard.exceptions import ex from sickbeard.common import cpu_presets +from itertools import ifilter db_lock = threading.Lock() @@ -113,6 +114,8 @@ class DBConnection: def mass_action(self, querylist, logTransaction=False): with db_lock: + # remove None types + querylist = [i for i in querylist if i!=None] if querylist == None: return diff --git a/sickbeard/network_timezones.py b/sickbeard/network_timezones.py index 3c7bd0c9..d4548748 100644 --- a/sickbeard/network_timezones.py +++ b/sickbeard/network_timezones.py @@ -186,7 +186,7 @@ def update_network_dict(): L = list(va for va in old_d) ql.append(["DELETE FROM network_timezones WHERE network_name IN (" + ','.join(['?'] * len(L)) + ")", L]) # change all network timezone infos at once (much faster) - if len(ql) > 0: + if ql: myDB.mass_action(ql) load_network_dict() diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 201aa89d..d768ebfd 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -961,7 +961,7 @@ class PostProcessor(object): else: self._log(u"Couldn't find release in snatch history", logger.WARNING) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) @@ -1038,7 +1038,7 @@ class PostProcessor(object): ep_obj.createMetaFiles() sql_l.append(ep_obj.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) diff --git a/sickbeard/providers/btn.py b/sickbeard/providers/btn.py index aadae43d..66e6bbb4 100644 --- a/sickbeard/providers/btn.py +++ b/sickbeard/providers/btn.py @@ -341,8 +341,9 @@ class BTNCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) else: raise AuthException( diff --git a/sickbeard/providers/hdbits.py b/sickbeard/providers/hdbits.py index 5ae61bd6..925bff1c 100644 --- a/sickbeard/providers/hdbits.py +++ b/sickbeard/providers/hdbits.py @@ -233,8 +233,9 @@ class HDBitsCache(tvcache.TVCache): if ci is not None: ql.append(ci) - myDB = self._getDB() - myDB.mass_action(ql) + if ql: + myDB = self._getDB() + myDB.mass_action(ql) else: raise exceptions.AuthException( diff --git a/sickbeard/providers/hdtorrents.py b/sickbeard/providers/hdtorrents.py index e054dada..5de98cae 100644 --- a/sickbeard/providers/hdtorrents.py +++ b/sickbeard/providers/hdtorrents.py @@ -367,8 +367,9 @@ class HDTorrentsCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/iptorrents.py b/sickbeard/providers/iptorrents.py index c025c407..37afda01 100644 --- a/sickbeard/providers/iptorrents.py +++ b/sickbeard/providers/iptorrents.py @@ -308,8 +308,9 @@ class IPTorrentsCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py index 382d40f5..187b0058 100644 --- a/sickbeard/providers/kat.py +++ b/sickbeard/providers/kat.py @@ -445,8 +445,9 @@ class KATCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index b49e9d18..7affc1a7 100644 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -341,8 +341,9 @@ class NewznabCache(tvcache.TVCache): if ci is not None: ql.append(ci) - myDB = self._getDB() - myDB.mass_action(ql) + if ql: + myDB = self._getDB() + myDB.mass_action(ql) else: raise AuthException( diff --git a/sickbeard/providers/nextgen.py b/sickbeard/providers/nextgen.py index 9cc51c88..c988c827 100644 --- a/sickbeard/providers/nextgen.py +++ b/sickbeard/providers/nextgen.py @@ -357,8 +357,9 @@ class NextGenCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/publichd.py b/sickbeard/providers/publichd.py index 200a6693..8d8c7b5f 100644 --- a/sickbeard/providers/publichd.py +++ b/sickbeard/providers/publichd.py @@ -337,8 +337,9 @@ class PublicHDCache(tvcache.TVCache): if ci is not None: ql.append(ci) - myDB = self._getDB() - myDB.mass_action(ql) + if ql: + myDB = self._getDB() + myDB.mass_action(ql) def _parseItem(self, item): diff --git a/sickbeard/providers/scc.py b/sickbeard/providers/scc.py index b2c16372..7d7c9110 100644 --- a/sickbeard/providers/scc.py +++ b/sickbeard/providers/scc.py @@ -352,8 +352,9 @@ class SCCCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/speedcd.py b/sickbeard/providers/speedcd.py index e54647b2..b42406c9 100644 --- a/sickbeard/providers/speedcd.py +++ b/sickbeard/providers/speedcd.py @@ -292,8 +292,9 @@ class SpeedCDCache(tvcache.TVCache): if ci is not None: ql.append(ci) - myDB = self._getDB() - myDB.mass_action(ql) + if ql: + myDB = self._getDB() + myDB.mass_action(ql) def _parseItem(self, item): diff --git a/sickbeard/providers/thepiratebay.py b/sickbeard/providers/thepiratebay.py index bbd18f56..3b1c56c9 100644 --- a/sickbeard/providers/thepiratebay.py +++ b/sickbeard/providers/thepiratebay.py @@ -427,8 +427,9 @@ class ThePirateBayCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/torrentday.py b/sickbeard/providers/torrentday.py index e6dc09a1..48660d10 100644 --- a/sickbeard/providers/torrentday.py +++ b/sickbeard/providers/torrentday.py @@ -315,8 +315,9 @@ class TorrentDayCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/providers/torrentleech.py b/sickbeard/providers/torrentleech.py index 74af3ad6..db694040 100644 --- a/sickbeard/providers/torrentleech.py +++ b/sickbeard/providers/torrentleech.py @@ -311,8 +311,9 @@ class TorrentLeechCache(tvcache.TVCache): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) def _parseItem(self, item): diff --git a/sickbeard/search.py b/sickbeard/search.py index 42d5f9a5..4a20de07 100644 --- a/sickbeard/search.py +++ b/sickbeard/search.py @@ -174,7 +174,7 @@ def snatchEpisode(result, endStatus=SNATCHED): if curEpObj.status not in Quality.DOWNLOADED: notifiers.notify_snatch(curEpObj._format_pattern('%SN - %Sx%0E - %EN - %QN')) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 79dfcace..eeb9ed00 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -421,7 +421,7 @@ class TVShow(object): sql_l.append(curEpisode.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) @@ -542,7 +542,7 @@ class TVShow(object): scannedEps[season][episode] = True - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) @@ -712,7 +712,7 @@ class TVShow(object): with curEp.lock: sql_l.append(curEp.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) @@ -1039,7 +1039,7 @@ class TVShow(object): if sickbeard.AIRDATE_EPISODES: self.airdateModifyStamp(curEp) - if len(sql_l): + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) @@ -2312,6 +2312,6 @@ class TVEpisode(object): for relEp in self.relatedEps: sql_l.append(relEp.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index c6ce10f0..101c17d9 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -128,8 +128,9 @@ class TVCache(): if ci is not None: cl.append(ci) - myDB = self._getDB() - myDB.mass_action(cl) + if cl: + myDB = self._getDB() + myDB.mass_action(cl) else: raise AuthException( diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index c37c1c98..60314d51 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -1011,7 +1011,7 @@ class CMD_EpisodeSetStatus(ApiCall): start_backlog = True ep_results.append(_epResult(RESULT_SUCCESS, epObj)) - if len(sql_l): + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 70f219f3..db610c5a 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -3528,7 +3528,7 @@ class Home: # mass add to database sql_l.append(epObj.get_sql()) - if len(sql_l) > 0: + if sql_l: myDB = db.DBConnection() myDB.mass_action(sql_l)