6"""Module that finds and runs a binary by looking in the likely locations."""
15 """Runs a program from the command line and returns stdout.
18 args: Command line to run, as a list of string parameters. args[0]
is the
22 stdout
from the program,
as a single string.
25 Exception: the program exited
with a nonzero
return code.
27 proc = subprocess.Popen(args,
28 stdout=subprocess.PIPE,
29 stderr=subprocess.PIPE)
30 (stdout, stderr) = proc.communicate()
31 if proc.returncode
is not 0:
32 raise Exception(
'command "%s" failed: %s' % (args, stderr))
37 """Returns path to an existing program binary.
40 program: Basename of the program to find (e.g., 'render_pictures').
43 Absolute path to the program binary,
as a string.
46 Exception: unable to find the program binary.
48 trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
50 possible_paths = [os.path.join(trunk_path, 'out',
'Release', program),
51 os.path.join(trunk_path,
'out',
'Debug', program),
52 os.path.join(trunk_path,
'out',
'Release',
54 os.path.join(trunk_path,
'out',
'Debug',
56 for try_path
in possible_paths:
57 if os.path.isfile(try_path):
59 raise Exception(
'cannot find %s in paths %s; maybe you need to '
60 'build %s?' % (program, possible_paths, program))