From e3f896d316333d9ccd528f5ba24e0da5988cba23 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Wed, 30 Apr 2014 13:30:46 +0930 Subject: [PATCH] clean exit for NZBGet. --- nzbtomedia/__init__.py | 15 ++++++++++++--- nzbtomedia/logger.py | 4 +++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index 1b8a1073..290565d2 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -181,7 +181,10 @@ def initialize(section=None): except: print 'Sorry, you MUST add the nzbToMedia folder to the PYTHONPATH environment variable' print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.' - sys.exit(1) + if os.environ.has_key('NZBOP_SCRIPTDIR'): + sys.exit(NZBGET_POSTPROCESS_ERROR) + else: + sys.exit(1) if not makeDir(LOG_DIR): print("!!! No log folder, logging to screen only!") @@ -192,13 +195,19 @@ def initialize(section=None): # run migrate to convert old cfg to new style cfg plus fix any cfg missing values/options. if not config.migrate(): logger.error("Unable to migrate config file %s, exiting ..." % (CONFIG_FILE)) - sys.exit(-1) + if os.environ.has_key('NZBOP_SCRIPTDIR'): + sys.exit(NZBGET_POSTPROCESS_ERROR) + else: + sys.exit(-1) # run migrate to convert NzbGet data from old cfg style to new cfg style if os.environ.has_key('NZBOP_SCRIPTDIR'): if not config.addnzbget(): logger.error("Unable to migrate NzbGet config file %s, exiting ..." % (CONFIG_FILE)) - sys.exit(-1) + if os.environ.has_key('NZBOP_SCRIPTDIR'): + sys.exit(NZBGET_POSTPROCESS_ERROR) + else: + sys.exit(-1) # load newly migrated config logger.info("Loading config from [%s]" % (CONFIG_FILE)) CFG = config() diff --git a/nzbtomedia/logger.py b/nzbtomedia/logger.py index 91522b2e..3a3b3fab 100644 --- a/nzbtomedia/logger.py +++ b/nzbtomedia/logger.py @@ -223,7 +223,9 @@ class NTMRotatingLogHandler(object): def log_error_and_exit(self, error_msg): log(error_msg, ERROR) - if not self.console_logging: + if os.environ.has_key('NZBOP_SCRIPTDIR'): + sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) + elif not self.console_logging: sys.exit(error_msg.encode(nzbtomedia.SYS_ENCODING, 'xmlcharrefreplace')) else: sys.exit(1)