From db9b65336178c6cd2207e481e38d74c822ae97ee Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sun, 23 Feb 2014 11:15:50 +1030 Subject: [PATCH] use improved status testing on indepenent scripts. --- DeleteSamples.py | 42 +++++++++++++++--------------------------- ResetDateTime.py | 42 +++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 54 deletions(-) diff --git a/DeleteSamples.py b/DeleteSamples.py index e53d458f..e8e1f92d 100755 --- a/DeleteSamples.py +++ b/DeleteSamples.py @@ -54,7 +54,6 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 print "Script triggered from NZBGet (11.0 or later)." # NZBGet argv: all passed as environment variables. - clientAgent = "nzbget" # Exit codes used by NZBGet POSTPROCESS_PARCHECK=92 POSTPROCESS_SUCCESS=93 @@ -65,50 +64,39 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 status = 0 if os.environ['NZBOP_UNPACK'] != 'yes': - print "Please enable option \"Unpack\" in nzbget configuration file, exiting" + Logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting") sys.exit(POSTPROCESS_ERROR) # Check par status if os.environ['NZBPP_PARSTATUS'] == '3': - print "Par-check successful, but Par-repair disabled, exiting" + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + Logger.info("Please check your Par-repair settings for future downloads.") sys.exit(POSTPROCESS_NONE) - if os.environ['NZBPP_PARSTATUS'] == '1': - print "Par-check failed, setting status \"failed\"" + if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': + Logger.warning("Par-repair failed, setting status \"failed\"") status = 1 # Check unpack status if os.environ['NZBPP_UNPACKSTATUS'] == '1': - print "Unpack failed, setting status \"failed\"" + Logger.warning("Unpack failed, setting status \"failed\"") status = 1 - if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] != '2': - # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': + # Unpack was skipped due to nzb-file properties or due to errors during par-check - for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): - for file in filenames: - fileExtension = os.path.splitext(file)[1] - - if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: - print "Post-Process: Archive files exist but unpack skipped, setting status \"failed\"" - status = 1 - break - - if fileExtension in ['.par2']: - print "Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\"g" - status = 1 - break - - if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")) and not status == 1: - print "Post-Process: _brokenlog.txt exists, download is probably damaged, exiting" + if os.environ['NZBPP_HEALTH'] < 1000: + Logger.warning("Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \"failed\"") + Logger.info("Please check your Par-check/repair settings for future downloads.") status = 1 - if not status == 1: - print "Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful" + else: + Logger.info("Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful") + Logger.info("Please check your Par-check/repair settings for future downloads.") # Check if destination directory exists (important for reprocessing of history items) if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): - print "Post-Process: Nothing to post-process: destination directory ", os.environ['NZBPP_DIRECTORY'], "doesn't exist" + Logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status \"failed\"", os.environ['NZBPP_DIRECTORY']) status = 1 # All checks done, now launching the script. diff --git a/ResetDateTime.py b/ResetDateTime.py index af99361f..1db9976f 100755 --- a/ResetDateTime.py +++ b/ResetDateTime.py @@ -22,7 +22,6 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 print "Script triggered from NZBGet (11.0 or later)." # NZBGet argv: all passed as environment variables. - clientAgent = "nzbget" # Exit codes used by NZBGet POSTPROCESS_PARCHECK=92 POSTPROCESS_SUCCESS=93 @@ -33,50 +32,39 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5 status = 0 if os.environ['NZBOP_UNPACK'] != 'yes': - print "Please enable option \"Unpack\" in nzbget configuration file, exiting" + Logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting") sys.exit(POSTPROCESS_ERROR) # Check par status if os.environ['NZBPP_PARSTATUS'] == '3': - print "Par-check successful, but Par-repair disabled, exiting" + Logger.warning("Par-check successful, but Par-repair disabled, exiting") + Logger.info("Please check your Par-repair settings for future downloads.") sys.exit(POSTPROCESS_NONE) - if os.environ['NZBPP_PARSTATUS'] == '1': - print "Par-check failed, setting status \"failed\"" + if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': + Logger.warning("Par-repair failed, setting status \"failed\"") status = 1 # Check unpack status if os.environ['NZBPP_UNPACKSTATUS'] == '1': - print "Unpack failed, setting status \"failed\"" + Logger.warning("Unpack failed, setting status \"failed\"") status = 1 - if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] != '2': - # Unpack is disabled or was skipped due to nzb-file properties or due to errors during par-check + if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': + # Unpack was skipped due to nzb-file properties or due to errors during par-check - for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): - for file in filenames: - fileExtension = os.path.splitext(file)[1] - - if fileExtension in ['.rar', '.7z'] or os.path.splitext(fileExtension)[1] in ['.rar', '.7z']: - print "Post-Process: Archive files exist but unpack skipped, setting status \"failed\"" - status = 1 - break - - if fileExtension in ['.par2']: - print "Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\"g" - status = 1 - break - - if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")) and not status == 1: - print "Post-Process: _brokenlog.txt exists, download is probably damaged, exiting" + if os.environ['NZBPP_HEALTH'] < 1000: + Logger.warning("Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \"failed\"") + Logger.info("Please check your Par-check/repair settings for future downloads.") status = 1 - if not status == 1: - print "Neither archive- nor par2-files found, _brokenlog.txt doesn't exist, considering download successful" + else: + Logger.info("Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful") + Logger.info("Please check your Par-check/repair settings for future downloads.") # Check if destination directory exists (important for reprocessing of history items) if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): - print "Post-Process: Nothing to post-process: destination directory ", os.environ['NZBPP_DIRECTORY'], "doesn't exist" + Logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status \"failed\"", os.environ['NZBPP_DIRECTORY']) status = 1 # All checks done, now launching the script.