Skip to content

Commit 6670e47

Browse files
committed
Merge pull request #896 from thezoggy/dev--logging_tweaks
logging tweaks - port from conjuro branch
2 parents 5f3f677 + 9a08c0f commit 6670e47

File tree

5 files changed

+58
-39
lines changed

5 files changed

+58
-39
lines changed

sickbeard/databases/mainDB.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def execute(self):
446446
self.incDBVersion()
447447

448448

449-
# included in build 507 (2014-0#-##)
449+
# included in build 507 (2014-11-16)
450450
class CleanupHistoryAndSpecials(AddRequireAndIgnoreWords):
451451
""" Cleanup older history entries and set specials from wanted to skipped """
452452

@@ -560,7 +560,7 @@ def execute(self):
560560
self.connection.action("VACUUM")
561561

562562

563-
# included in build 507 (2014-0#-##)
563+
# included in build 507 (2014-11-16)
564564
class AddSkipNotifications(CleanupHistoryAndSpecials):
565565
""" Adding column skip_notices to tv_shows """
566566

@@ -577,7 +577,7 @@ def execute(self):
577577
self.incDBVersion()
578578

579579

580-
# included in build 507 (2014-0#-##)
580+
# included in build 507 (2014-11-16)
581581
class AddHistorySource(AddSkipNotifications):
582582
""" Adding column source to history """
583583

sickbeard/nzbget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def sendNZB(nzb):
5252

5353
url = urlparse.urlunsplit((scheme, netloc, u"/xmlrpc", "", ""))
5454

55-
logger.log(u"Sending NZB to NZBGet")
55+
logger.log(u"Sending NZB to NZBGet: %s" % nzb.name)
5656
logger.log(u"NZBGet URL: " + url, logger.DEBUG)
5757

5858
nzbGetRPC = xmlrpclib.ServerProxy(url.encode("utf-8", 'ignore'))

sickbeard/sab.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
# along with Sick Beard. If not, see <http://www.gnu.org/licenses/>.
1818

1919

20-
21-
import urllib, httplib
20+
import urllib
21+
import httplib
2222
import datetime
2323

2424
import sickbeard
2525

2626
from lib import MultipartPostHandler
27-
import urllib2, cookielib
27+
import urllib2
28+
import cookielib
2829
try:
2930
import json
3031
except ImportError:
@@ -34,22 +35,23 @@
3435
from sickbeard import logger
3536
from sickbeard.exceptions import ex
3637

38+
3739
def sendNZB(nzb):
3840
"""
3941
Sends an NZB to SABnzbd via the API.
40-
42+
4143
nzb: The NZBSearchResult object to send to SAB
4244
"""
4345

4446
# set up a dict with the URL params in it
4547
params = {}
46-
if sickbeard.SAB_USERNAME != None:
48+
if sickbeard.SAB_USERNAME is not None:
4749
params['ma_username'] = sickbeard.SAB_USERNAME
48-
if sickbeard.SAB_PASSWORD != None:
50+
if sickbeard.SAB_PASSWORD is not None:
4951
params['ma_password'] = sickbeard.SAB_PASSWORD
50-
if sickbeard.SAB_APIKEY != None:
52+
if sickbeard.SAB_APIKEY is not None:
5153
params['apikey'] = sickbeard.SAB_APIKEY
52-
if sickbeard.SAB_CATEGORY != None:
54+
if sickbeard.SAB_CATEGORY is not None:
5355
params['cat'] = sickbeard.SAB_CATEGORY
5456

5557
# if it aired recently make it high priority
@@ -69,14 +71,14 @@ def sendNZB(nzb):
6971

7072
url = sickbeard.SAB_HOST + "api?" + urllib.urlencode(params)
7173

72-
logger.log(u"Sending NZB to SABnzbd")
73-
logger.log(u"URL: " + url, logger.DEBUG)
74+
logger.log(u"Sending NZB to SABnzbd: %s" % nzb.name)
75+
logger.log(u"SABnzbd URL: " + url, logger.DEBUG)
7476

7577
try:
76-
# if we have the URL to an NZB then we've built up the SAB API URL already so just call it
78+
# if we have the URL to an NZB then we've built up the SAB API URL already so just call it
7779
if nzb.resultType == "nzb":
7880
f = urllib.urlopen(url)
79-
81+
8082
# if we are uploading the NZB data to SAB then we need to build a little POST form and send it
8183
elif nzb.resultType == "nzbdata":
8284
cookies = cookielib.CookieJar()
@@ -97,7 +99,7 @@ def sendNZB(nzb):
9799
return False
98100

99101
# this means we couldn't open the connection or something just as bad
100-
if f == None:
102+
if f is None:
101103
logger.log(u"No data returned from SABnzbd, NZB not sent", logger.ERROR)
102104
return False
103105

@@ -108,7 +110,7 @@ def sendNZB(nzb):
108110
logger.log(u"Error trying to get result from SAB, NZB not sent: " + ex(e), logger.ERROR)
109111
return False
110112

111-
# SAB shouldn't return a blank result, this most likely (but not always) means that it timed out and didn't recieve the NZB
113+
# SAB shouldn't return a blank result, this most likely (but not always) means that it timed out and didn't receive the NZB
112114
if len(result) == 0:
113115
logger.log(u"No data returned from SABnzbd, NZB not sent", logger.ERROR)
114116
return False
@@ -129,6 +131,7 @@ def sendNZB(nzb):
129131
logger.log(u"Unknown failure sending NZB to sab. Return text is: " + sabText, logger.ERROR)
130132
return False
131133

134+
132135
def _checkSabResponse(f):
133136
try:
134137
result = f.readlines()
@@ -156,6 +159,7 @@ def _checkSabResponse(f):
156159
else:
157160
return True, sabText
158161

162+
159163
def _sabURLOpenSimple(url):
160164
try:
161165
f = urllib.urlopen(url)
@@ -165,15 +169,16 @@ def _sabURLOpenSimple(url):
165169
except httplib.InvalidURL, e:
166170
logger.log(u"Invalid SAB host, check your config: " + ex(e), logger.ERROR)
167171
return False, "Invalid SAB host"
168-
if f == None:
172+
if f is None:
169173
logger.log(u"No data returned from SABnzbd", logger.ERROR)
170174
return False, "No data returned from SABnzbd"
171175
else:
172176
return True, f
173177

178+
174179
def getSabAccesMethod(host=None, username=None, password=None, apikey=None):
175180
url = host + "api?mode=auth"
176-
181+
177182
result, f = _sabURLOpenSimple(url)
178183
if not result:
179184
return False, f
@@ -184,18 +189,19 @@ def getSabAccesMethod(host=None, username=None, password=None, apikey=None):
184189

185190
return True, sabText
186191

192+
187193
def testAuthentication(host=None, username=None, password=None, apikey=None):
188194
"""
189195
Sends a simple API request to SAB to determine if the given connection information is connect
190-
196+
191197
host: The host where SAB is running (incl port)
192198
username: The username to use for the HTTP request
193199
password: The password to use for the HTTP request
194200
apikey: The API key to provide to SAB
195-
201+
196202
Returns: A tuple containing the success boolean and a message
197203
"""
198-
204+
199205
# build up the URL parameters
200206
params = {}
201207
params['mode'] = 'queue'
@@ -204,7 +210,7 @@ def testAuthentication(host=None, username=None, password=None, apikey=None):
204210
params['ma_password'] = password
205211
params['apikey'] = apikey
206212
url = host + "api?" + urllib.urlencode(params)
207-
213+
208214
# send the test request
209215
logger.log(u"SABnzbd test URL: " + url, logger.DEBUG)
210216
result, f = _sabURLOpenSimple(url)
@@ -215,6 +221,5 @@ def testAuthentication(host=None, username=None, password=None, apikey=None):
215221
result, sabText = _checkSabResponse(f)
216222
if not result:
217223
return False, sabText
218-
224+
219225
return True, "Success"
220-

sickbeard/searchBacklog.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from sickbeard import search_queue
2828
from sickbeard import logger
2929
from sickbeard import ui
30-
#from sickbeard.common import *
30+
3131

3232
class BacklogSearchScheduler(scheduler.Scheduler):
3333

@@ -41,6 +41,7 @@ def nextRun(self):
4141
else:
4242
return datetime.date.fromordinal(self.action._lastBacklog + self.action.cycleTime)
4343

44+
4445
class BacklogSearcher:
4546

4647
def __init__(self):
@@ -65,7 +66,7 @@ def getProgressIndicator(self):
6566
return None
6667

6768
def am_running(self):
68-
logger.log(u"amWaiting: "+str(self.amWaiting)+", amActive: "+str(self.amActive), logger.DEBUG)
69+
logger.log(u"amWaiting: " + str(self.amWaiting) + ", amActive: " + str(self.amActive), logger.DEBUG)
6970
return (not self.amWaiting) and self.amActive
7071

7172
def searchBacklog(self, which_shows=None):
@@ -75,7 +76,20 @@ def searchBacklog(self, which_shows=None):
7576
else:
7677
show_list = sickbeard.showList
7778

78-
if self.amActive == True:
79+
def titler(x):
80+
if not x:
81+
return x
82+
if not x.lower().startswith('a to ') and x.lower().startswith('a '):
83+
x = x[2:]
84+
elif x.lower().startswith('an '):
85+
x = x[3:]
86+
elif x.lower().startswith('the '):
87+
x = x[4:]
88+
return x
89+
# sort shows the same way we show them, makes it easier to follow along
90+
show_list = sorted(show_list, lambda x, y: cmp(titler(x.name), titler(y.name)))
91+
92+
if self.amActive is True:
7993
logger.log(u"Backlog is still running, not starting it again", logger.DEBUG)
8094
return
8195

@@ -101,9 +115,9 @@ def searchBacklog(self, which_shows=None):
101115
# figure out how many segments of air by date shows we're going to do
102116
air_by_date_segments = []
103117
for cur_id in [x.tvdbid for x in air_by_date_shows]:
104-
air_by_date_segments += self._get_air_by_date_segments(cur_id, fromDate)
118+
air_by_date_segments += self._get_air_by_date_segments(cur_id, fromDate)
105119

106-
logger.log(u"Air-by-date segments: "+str(air_by_date_segments), logger.DEBUG)
120+
logger.log(u"Air-by-date segments: " + str(air_by_date_segments), logger.DEBUG)
107121

108122
#totalSeasons = float(len(numSeasonResults) + len(air_by_date_segments))
109123
#numSeasonsDone = 0.0
@@ -121,14 +135,14 @@ def searchBacklog(self, which_shows=None):
121135

122136
for cur_segment in segments:
123137

124-
self.currentSearchInfo = {'title': curShow.name + " Season "+str(cur_segment)}
138+
self.currentSearchInfo = {'title': curShow.name + " Season " + str(cur_segment)}
125139

126140
backlog_queue_item = search_queue.BacklogQueueItem(curShow, cur_segment)
127141

128142
if not backlog_queue_item.wantSeason:
129-
logger.log(u"Nothing in season "+str(cur_segment)+" needs to be downloaded, skipping this season", logger.DEBUG)
143+
logger.log(u"Nothing in season " + str(cur_segment) + " needs to be downloaded, skipping this season", logger.DEBUG)
130144
else:
131-
sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) #@UndefinedVariable
145+
sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) # @UndefinedVariable
132146

133147
# don't consider this an actual backlog search if we only did recent eps
134148
# or if we only did certain shows
@@ -147,7 +161,7 @@ def _get_lastBacklog(self):
147161

148162
if len(sqlResults) == 0:
149163
lastBacklog = 1
150-
elif sqlResults[0]["last_backlog"] == None or sqlResults[0]["last_backlog"] == "":
164+
elif sqlResults[0]["last_backlog"] is None or sqlResults[0]["last_backlog"] == "":
151165
lastBacklog = 1
152166
else:
153167
lastBacklog = int(sqlResults[0]["last_backlog"])
@@ -174,11 +188,11 @@ def _get_air_by_date_segments(self, tvdb_id, fromDate):
174188
cur_date = datetime.date.fromordinal(int(cur_result["airdate"]))
175189
cur_date_str = str(cur_date)[:7]
176190
cur_tvdb_id = int(cur_result["showid"])
177-
191+
178192
cur_result_tuple = (cur_tvdb_id, cur_date_str)
179193
if cur_result_tuple not in air_by_date_segments:
180194
air_by_date_segments.append(cur_result_tuple)
181-
195+
182196
return air_by_date_segments
183197

184198
def _set_lastBacklog(self, when):
@@ -193,7 +207,6 @@ def _set_lastBacklog(self, when):
193207
else:
194208
myDB.action("UPDATE info SET last_backlog=" + str(when))
195209

196-
197210
def run(self):
198211
try:
199212
self.searchBacklog()

sickbeard/search_queue.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def execute(self):
143143

144144
def _changeMissingEpisodes(self):
145145

146-
logger.log(u"Changing all old missing episodes to status WANTED")
146+
logger.log(u"Changing all old missing episodes (UNAIRED) to status WANTED")
147147

148148
curDate = datetime.date.today().toordinal()
149149

@@ -215,6 +215,7 @@ def execute(self):
215215
search.snatchEpisode(curResult)
216216
time.sleep(5)
217217

218+
logger.log(u"Finished searching for episodes from " + self.show.name + " season " + str(self.segment))
218219
self.finish()
219220

220221
def _need_any_episodes(self, statusResults, bestQualities):

0 commit comments

Comments
 (0)