326
326
# The actions call Python os functions but print actions and handle dryness.
327
327
# May still throw os exceptions if errors occur.
330
"""Represents an error when running a program (nonzero return)."""
331
def __init__(self, prog, retcode):
333
self.retcode = retcode
335
return str(self.prog) + " returned " + repr(self.retcode)
329
337
def action_runprog(prog, args, dry):
330
338
"""Runs a unix program. Searches in $PATH. Synchronous (waits for the
331
339
program to return). Runs in the current environment. First prints the
332
340
action as a "bash" line.
342
Throws a RunError with a retcode of the return value of the program,
343
if the program did not return 0.
334
345
prog: String. Name of the program. (No path required, if in $PATH).
335
346
args: [String]. Arguments to the program.
336
347
dry: Bool. If True, prints but does not execute.
338
349
print prog, string.join(args, ' ')
340
os.spawnvp(os.P_WAIT, prog, args)
351
ret = os.spawnvp(os.P_WAIT, prog, args)
353
raise RunError(prog, ret)
342
355
def action_mkdir(path):
343
356
"""Calls mkdir. Silently ignored if the directory already exists."""