From 7eb21e55c1fc869579e77a3553f9cc8382a2b1d8 Mon Sep 17 00:00:00 2001 From: andrewk Date: Mon, 14 Sep 2009 23:30:13 +0000 Subject: [PATCH] Added die_on_fail which outputs an error message and stops execution if a farm or terminal command fails git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1618 348d0f76-0448-11de-a6fe-93d51630548a --- python/farm_commands.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/farm_commands.py b/python/farm_commands.py index c81c53993..556fc12c8 100644 --- a/python/farm_commands.py +++ b/python/farm_commands.py @@ -1,13 +1,15 @@ #!/usr/bin/env python import os +import sys import subprocess import re #justPrintCommands = False -def cmd(cmd_str_from_user, farm_queue=False, output_head=None, just_print_commands=False, outputFile = None, waitID = None, jobName = None): - # if farm_queue is non-False, submits to queue, other +def cmd(cmd_str_from_user, farm_queue=False, output_head=None, just_print_commands=False, outputFile = None, waitID = None, jobName = None, die_on_fail = False): + """if farm_queue != False, submits to queue, other +die_on_fail_msg: if != None, die on command failure (non-zero return) and show die_on_fail_msg""" if farm_queue: if outputFile <> None: @@ -47,5 +49,7 @@ def cmd(cmd_str_from_user, farm_queue=False, output_head=None, just_print_comman status = os.system(cmd_str) if not farm_queue: print "<<< Exit code:", status,"\n" + if die_on_fail != None and status != 0: + print "### Failed with exit code "+str(status)+" while executing command "+cmd_str_from_user + sys.exit() return int(status) -