From 80a0a6f28df2140a2915bd2f25f8e5424b9b3036 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Sat, 9 Nov 2013 10:03:12 +1030 Subject: [PATCH] change the call method and add succesCodes. fixes #185 --- TorrentToMedia.py | 14 +++++++++++--- autoProcessMedia.cfg.sample | 2 ++ extractor/extractor.py | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 1cded274..92e2ab96 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -10,7 +10,7 @@ import datetime import time import re from sets import Set -from subprocess import call +from subprocess import call, Popen # Custom imports import autoProcess.migratecfg as migratecfg @@ -286,9 +286,16 @@ def external_script(outputDestination): continue Logger.info("Running script %s on file %s.", command, filePath) try: - result = call(command) + p = Popen(command) + res = p.wait() + if res in user_script_successCodes: Linux returns 0 for successful. + Logger.info("UserScript %s was successfull", command[0]) + else: + Logger.error("UserScript %s has failed with return code: %s", command[0], res) + Logger.info("If the UserScript completed successfully you should add "%s" to the user_script_successCodes", res) + result = 1 except: - Logger.exception("UserScript %s has failed", command) + Logger.exception("UserScript %s has failed", command[0]) result = 1 final_result = final_result + result @@ -374,6 +381,7 @@ if __name__ == "__main__": user_script_mediaExtensions = (config.get("UserScript", "user_script_mediaExtensions")).split(',') user_script = config.get("UserScript", "user_script_path") user_script_param = (config.get("UserScript", "user_script_param")).split(',') + user_script_successCodes = (config.get("UserScript", "user_script_successCodes")).split(',') user_script_clean = int(config.get("UserScript", "user_script_clean")) user_delay = int(config.get("UserScript", "delay")) diff --git a/autoProcessMedia.cfg.sample b/autoProcessMedia.cfg.sample index 51c30b57..c2897fdc 100644 --- a/autoProcessMedia.cfg.sample +++ b/autoProcessMedia.cfg.sample @@ -139,6 +139,8 @@ user_script_path = /media/test/script/script.sh #for example FP,FN,DN for file path (absolute file name with path), file anme, absolute directory name (with path). #So the result is /media/test/script/script.sh FP FN DN user_script_param = FN +#Specify the successcodes returned by the user script as a comma separated list. Linux default is 0 +user_script_successCodes = 0 #Clean after? Note that delay function is used to prevent possible mistake :) Delay is intended as seconds user_script_clean = 1 delay = 120 diff --git a/extractor/extractor.py b/extractor/extractor.py index bf6b1833..8044684a 100644 --- a/extractor/extractor.py +++ b/extractor/extractor.py @@ -119,7 +119,7 @@ def extract(filePath, outputDestination): cmd.append(filePath) # add filePath to final cmd arg. p = Popen(cmd) # should extract files fine. res = p.wait() - if res >= 0: # for windows chp returns process id if successful or -1*Error code. Linus returns 0 for successful. + if res >= 0: # for windows chp returns process id if successful or -1*Error code. Linux returns 0 for successful. Logger.info("EXTRACTOR: Extraction was successful for %s to %s", filePath, outputDestination) else: Logger.error("EXTRACTOR: Extraction failed for %s. 7zip result was %s", filePath, res)