<s> import os . path <EOL> import subprocess <EOL> class BinaryNotFoundError ( Exception ) : <EOL> pass <EOL> class CommandExecutionError ( Exception ) : <EOL> def __init__ ( self , errorcode ) : <EOL> self . errorcode = errorcode <EOL> def __str__ ( self ) : <EOL> return repr ( '<STR_LIT>' ) <EOL> def find_binary ( name ) : <EOL> dirs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for dir in dirs : <EOL> path = os . path . join ( dir , name ) <EOL> if os . path . exists ( path ) : <EOL> return path <EOL> raise BinaryNotFoundError ( '<STR_LIT>' + name + '<STR_LIT>' + '<STR_LIT>' ) <EOL> def execute ( args ) : <EOL> proc = subprocess . Popen ( args , stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> output = proc . stdout . read ( ) <EOL> if proc . wait ( ) == <NUM_LIT:0> : <EOL> return output <EOL> raise CommandExecutionError ( proc . returncode ) </s>
