~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2007-12-20 23:55:36 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:108
setup.py: Added RunError class. action_runprog now throws a RunError if the
    program it called did not return 0 (so the build stops with an exception
    if any of the actions fail).

Show diffs side-by-side

added added

removed removed

Lines of Context:
326
326
# The actions call Python os functions but print actions and handle dryness.
327
327
# May still throw os exceptions if errors occur.
328
328
 
 
329
class RunError:
 
330
    """Represents an error when running a program (nonzero return)."""
 
331
    def __init__(self, prog, retcode):
 
332
        self.prog = prog
 
333
        self.retcode = retcode
 
334
    def __str__(self):
 
335
        return str(self.prog) + " returned " + repr(self.retcode)
 
336
 
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.
333
341
 
 
342
    Throws a RunError with a retcode of the return value of the program,
 
343
    if the program did not return 0.
 
344
 
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.
337
348
    """
338
349
    print prog, string.join(args, ' ')
339
350
    if not dry:
340
 
        os.spawnvp(os.P_WAIT, prog, args)
 
351
        ret = os.spawnvp(os.P_WAIT, prog, args)
 
352
        if ret != 0:
 
353
            raise RunError(prog, ret)
341
354
 
342
355
def action_mkdir(path):
343
356
    """Calls mkdir. Silently ignored if the directory already exists."""