From 85737490385edca840cb601d67c4c2e66201eeba Mon Sep 17 00:00:00 2001 From: echel0n Date: Wed, 2 Apr 2014 04:27:43 -0700 Subject: [PATCH] Added in error handling to catch connection errors with autoFork. Logger config now defaults to process.log if no logfile is specified. --- autoProcess/autoProcessTV.py | 1 - autoProcess/autoSickBeardFork.py | 8 ++++++-- autoProcess/nzbToMediaUtil.py | 4 +++- tests/test_autofork.py | 3 +++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/autoProcess/autoProcessTV.py b/autoProcess/autoProcessTV.py index ff38de1e..09a7b0a1 100644 --- a/autoProcess/autoProcessTV.py +++ b/autoProcess/autoProcessTV.py @@ -8,7 +8,6 @@ from autoProcess.autoSickBeardFork import autoFork from nzbToMediaEnv import * from nzbToMediaUtil import * - Logger = logging.getLogger() class AuthURLOpener(urllib.FancyURLopener): diff --git a/autoProcess/autoSickBeardFork.py b/autoProcess/autoSickBeardFork.py index b8f317de..c1aef3c9 100644 --- a/autoProcess/autoSickBeardFork.py +++ b/autoProcess/autoSickBeardFork.py @@ -24,7 +24,7 @@ class AuthURLOpener(urllib.FancyURLopener): self.numTries = 0 return urllib.FancyURLopener.open(self, url) -def autoFork(fork=None): +def autoFork(): # config settings section = "SickBeard" @@ -62,7 +62,11 @@ def autoFork(fork=None): url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork[1]) # attempting to auto-detect fork - urlObj = myOpener.openit(url) + try: + urlObj = myOpener.openit(url) + except IOError, e: + Logger.info("Could not connect to SickBeard to perform auto-fork detection!") + break if urlObj.getcode() == 200: detected = True diff --git a/autoProcess/nzbToMediaUtil.py b/autoProcess/nzbToMediaUtil.py index 15704431..fe2655c4 100644 --- a/autoProcess/nzbToMediaUtil.py +++ b/autoProcess/nzbToMediaUtil.py @@ -28,7 +28,9 @@ def safeName(name): return safename -def nzbtomedia_configure_logging(logfile): +def nzbtomedia_configure_logging(logfile=None): + if not logfile: + logfile = LOG_FILE logging.config.fileConfig(CONFIG_FILE) fileHandler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=1048576, backupCount=1, encoding='utf-8', delay=True) fileHandler.formatter = logging.Formatter('%(asctime)s|%(levelname)-7.7s %(message)s', '%H:%M:%S') diff --git a/tests/test_autofork.py b/tests/test_autofork.py index 89364ddf..c9fb55c0 100644 --- a/tests/test_autofork.py +++ b/tests/test_autofork.py @@ -1,3 +1,6 @@ +from autoProcess.nzbToMediaUtil import * from autoProcess.autoSickBeardFork import autoFork +nzbtomedia_configure_logging(LOG_FILE) + fork, params = autoFork() print fork, params \ No newline at end of file