#NEWLINE# def run_command( cmd , root , dst , input , params ) : #NEWLINE# #INDENT# "\n    Execute a command, and if successful write it's stdout to ``root``/``dst``.\n    " #NEWLINE# use_stdout = ( '{output}' not in cmd ) #NEWLINE# if ( not use_stdout ) : #NEWLINE# #INDENT# params [ 'output' ] = dst #NEWLINE# #UNINDENT# parsed_cmd = parse_command ( cmd , input = input , params = params ) #NEWLINE# ensure_dirs ( os . path . join ( root , dst ) ) #NEWLINE# logger . info ( 'Running [%s] from [%s]' , parsed_cmd , root ) #NEWLINE# proc = subprocess . Popen ( args = parsed_cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = True , cwd = use_stdout ) #NEWLINE# ( stdout , stderr ) = proc . communicate ( ) #NEWLINE# assert ( not proc . returncode ) , stderr #NEWLINE# if use_stdout : #NEWLINE# #INDENT# with open ( os . path . join ( root , dst ) , 'w' ) as fp : #NEWLINE# #INDENT# fp . write ( stdout )