#NEWLINE# def run_cmd( cmd , attempts = 1 ) : #NEWLINE# #INDENT# ' Runs a command attempts times, logging its output. Returns True if it\n    succeeds once, or False if it never does. ' #NEWLINE# try : #NEWLINE# #INDENT# for i in range ( attempts ) : #NEWLINE# #INDENT# proc = subprocess . Popen ( cmd , stdin = open ( devnull , 'r' ) ) #NEWLINE# proc . wait ( ) #NEWLINE# if ( not ( proc . returncode == 0 ) ) : #NEWLINE# #INDENT# print ( 'Command ' , str ( cmd ) , ' failed' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'Command ' , str ( cmd ) , ' succeeded.' ) #NEWLINE# return True #NEWLINE# #UNINDENT# sleep ( 3 ) #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# print ( 'Error while attempting to run command ' , cmd ) #NEWLINE# print ( e )