~launchpad-pqm/launchpad/devel

9492.1.1 by Karl Fogel
Add utilities/formatdoctest.py and utilities/migrater/, both brought
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Useful utilities."""
5
6
__metaclass__ = type
7
8
__all__ = [
9
    'fail',
10
    'log',
11
    'run',
12
    'spew',
13
    ]
14
15
16
import sys
17
import subprocess
18
19
20
SPACE = ' '
21
22
23
def fail(message, *args):
24
    print >> sys.stderr, 'FAIL:', message % args
25
    sys.exit(1)
26
27
28
def log(message, *args):
29
    print >> sys.stderr, message % args
30
31
32
def spew(message, *args):
33
    log(message, *args)
34
35
36
def run(*args):
37
    proc = subprocess.Popen(args)
38
    if proc.wait() != 0:
39
        if proc.stderr:
40
            log(proc.stderr)
41
        fail('[%d] %s', proc.returncode, SPACE.join(args))