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
This commit is contained in:
parent
118071cfd8
commit
7eb21e55c1
|
|
@ -1,13 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
#justPrintCommands = False
|
#justPrintCommands = False
|
||||||
|
|
||||||
def cmd(cmd_str_from_user, farm_queue=False, output_head=None, just_print_commands=False, outputFile = None, waitID = None, jobName = None):
|
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 is non-False, submits to queue, other
|
"""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 farm_queue:
|
||||||
if outputFile <> None:
|
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)
|
status = os.system(cmd_str)
|
||||||
if not farm_queue:
|
if not farm_queue:
|
||||||
print "<<< Exit code:", status,"\n"
|
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)
|
return int(status)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue