fix deletesamples and resetdatetimes.

This commit is contained in:
clinton-hall 2014-03-02 12:51:51 +10:30
parent 1522d61492
commit f89e8d1b6b
2 changed files with 32 additions and 22 deletions

View file

@ -64,43 +64,46 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
status = 0 status = 0
if os.environ['NZBOP_UNPACK'] != 'yes': if os.environ['NZBOP_UNPACK'] != 'yes':
Logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting") print "Please enable option \"Unpack\" in nzbget configuration file, exiting."
sys.exit(POSTPROCESS_ERROR) sys.exit(POSTPROCESS_ERROR)
# Check par status # Check par status
if os.environ['NZBPP_PARSTATUS'] == '3': if os.environ['NZBPP_PARSTATUS'] == '3':
Logger.warning("Par-check successful, but Par-repair disabled, exiting") print "Par-check successful, but Par-repair disabled, exiting".
Logger.info("Please check your Par-repair settings for future downloads.") print "Please check your Par-repair settings for future downloads."
sys.exit(POSTPROCESS_NONE) sys.exit(POSTPROCESS_NONE)
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4':
Logger.warning("Par-repair failed, setting status \"failed\"") print "Par-repair failed, setting status \"failed\"."
status = 1 status = 1
# Check unpack status # Check unpack status
if os.environ['NZBPP_UNPACKSTATUS'] == '1': if os.environ['NZBPP_UNPACKSTATUS'] == '1':
Logger.warning("Unpack failed, setting status \"failed\"") print "Unpack failed, setting status \"failed\"."
status = 1 status = 1
if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': 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 # Unpack was skipped due to nzb-file properties or due to errors during par-check
if os.environ['NZBPP_HEALTH'] < 1000: 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\"") print "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.") print "Please check your Par-check/repair settings for future downloads."
status = 1 status = 1
else: 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") print "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.") print "Please check your Par-check/repair settings for future downloads."
# Check if destination directory exists (important for reprocessing of history items) # Check if destination directory exists (important for reprocessing of history items)
if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): if not os.path.isdir(os.environ['NZBPP_DIRECTORY']):
Logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status \"failed\"", os.environ['NZBPP_DIRECTORY']) print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"."
status = 1 status = 1
# All checks done, now launching the script. # All checks done, now launching the script.
if status == 1:
sys.exit(POSTPROCESS_NONE)
mediaContainer = os.environ['NZBPO_MEDIAEXTENSIONS'].split(',') mediaContainer = os.environ['NZBPO_MEDIAEXTENSIONS'].split(',')
SampleIDs = os.environ['NZBPO_SAMPLEIDS'].split(',') SampleIDs = os.environ['NZBPO_SAMPLEIDS'].split(',')
for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']):

View file

@ -32,50 +32,57 @@ if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5
status = 0 status = 0
if os.environ['NZBOP_UNPACK'] != 'yes': if os.environ['NZBOP_UNPACK'] != 'yes':
Logger.error("Please enable option \"Unpack\" in nzbget configuration file, exiting") print "Please enable option \"Unpack\" in nzbget configuration file, exiting."
sys.exit(POSTPROCESS_ERROR) sys.exit(POSTPROCESS_ERROR)
# Check par status # Check par status
if os.environ['NZBPP_PARSTATUS'] == '3': if os.environ['NZBPP_PARSTATUS'] == '3':
Logger.warning("Par-check successful, but Par-repair disabled, exiting") print "Par-check successful, but Par-repair disabled, exiting".
Logger.info("Please check your Par-repair settings for future downloads.") print "Please check your Par-repair settings for future downloads."
sys.exit(POSTPROCESS_NONE) sys.exit(POSTPROCESS_NONE)
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4':
Logger.warning("Par-repair failed, setting status \"failed\"") print "Par-repair failed, setting status \"failed\"."
status = 1 status = 1
# Check unpack status # Check unpack status
if os.environ['NZBPP_UNPACKSTATUS'] == '1': if os.environ['NZBPP_UNPACKSTATUS'] == '1':
Logger.warning("Unpack failed, setting status \"failed\"") print "Unpack failed, setting status \"failed\"."
status = 1 status = 1
if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': 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 # Unpack was skipped due to nzb-file properties or due to errors during par-check
if os.environ['NZBPP_HEALTH'] < 1000: 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\"") print "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.") print "Please check your Par-check/repair settings for future downloads."
status = 1 status = 1
else: 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") print "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.") print "Please check your Par-check/repair settings for future downloads."
# Check if destination directory exists (important for reprocessing of history items) # Check if destination directory exists (important for reprocessing of history items)
if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): if not os.path.isdir(os.environ['NZBPP_DIRECTORY']):
Logger.error("Nothing to post-process: destination directory %s doesn't exist. Setting status \"failed\"", os.environ['NZBPP_DIRECTORY']) print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"."
status = 1 status = 1
# All checks done, now launching the script. # All checks done, now launching the script.
if status == 1:
sys.exit(POSTPROCESS_NONE)
directory = os.path.normpath(os.environ['NZBPP_DIRECTORY']) directory = os.path.normpath(os.environ['NZBPP_DIRECTORY'])
for dirpath, dirnames, filenames in os.walk(directory): for dirpath, dirnames, filenames in os.walk(directory):
for file in filenames: for file in filenames:
filepath = os.path.join(dirpath, file) filepath = os.path.join(dirpath, file)
print "reseting datetime for file", filepath print "reseting datetime for file", filepath
try:
os.utime(filepath, None) os.utime(filepath, None)
continue continue
except:
print "Error: unable to reset time for file", filePath
sys.exit(POSTPROCESS_ERROR)
sys.exit(POSTPROCESS_SUCCESS) sys.exit(POSTPROCESS_SUCCESS)
else: else: