#NEWLINE# def invoke( cmd , check_rc = True , check_output = False ) : #NEWLINE# #INDENT# ' log a command, run it, and (usually) fail if it fails ' #NEWLINE# log = get_logger ( 'SHELL' ) #NEWLINE# log ( cmd ) #NEWLINE# if check_output : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return subprocess . check_output ( cmd , shell = True ) #NEWLINE# #UNINDENT# except subprocess . CalledProcessError : #NEWLINE# #INDENT# return '' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# rc = os . system ( cmd ) #NEWLINE# if ( check_rc and ( not ( rc == 0 ) ) ) : #NEWLINE# #INDENT# msg = ( 'command failed, rc: %s' % rc ) #NEWLINE# log ( msg ) #NEWLINE# raise Exception ( msg ) #NEWLINE# #UNINDENT# return rc