8
from subprocess import CalledProcessError
12
"""Run the command with the given arguments.
14
The first argument is the path to the command to run, subsequent arguments
15
are command-line arguments to be passed.
17
process = subprocess.Popen(args, stdout=subprocess.PIPE,
18
stderr=subprocess.PIPE, close_fds=True)
19
stdout, stderr = process.communicate()
20
if process.returncode:
21
raise subprocess.CalledProcessError(
22
process.returncode, repr(args), output=stdout+stderr)
26
def command(*base_args):
27
"""Return a callable that will run the given command with any arguments.
29
The first argument is the path to the command to run, subsequent arguments
30
are command-line arguments to "bake into" the returned callable.
32
The callable runs the given executable and also takes arguments that will
33
be appeneded to the "baked in" arguments.
35
For example, this code will list a file named "foo" (if it exists):
37
ls_foo = command('/bin/ls', 'foo')
40
While this invocation will list "foo" and "bar" (assuming they exist):
44
def callable_command(*args):
45
all_args = base_args + args
48
return callable_command
51
log = command('juju-log')
54
def install_extra_repository(extra_repository):
56
run('apt-add-repository', extra_repository)
57
run('apt-get', 'update')
58
except subprocess.CalledProcessError as e:
59
log('Error adding repository: ' + extra_repository)
64
def install_packages():
65
apt_get_install = command('apt-get', 'install', '-y', '--force-yes')
66
apt_get_install('bzr', 'python-boto')
67
install_extra_repository('ppa:yellow/ppa')
68
apt_get_install('python-shell-toolbox')
73
# These modules depend on shelltoolbox being installed so they must not be
74
# imported until that package is available.
10
75
from helpers import (
18
80
from local import (
24
86
def cleanup(buildbot_dir):
25
apt_get_install('bzr', 'python-boto')
26
87
# Since we may be installing into a pre-existing service, ensure the
27
88
# buildbot directory is removed.
28
89
if os.path.exists(buildbot_dir):
30
91
run('buildbot', 'stop', buildbot_dir)
31
except (CalledProcessError, OSError):
92
except (subprocess.CalledProcessError, OSError):
32
93
# This usually happens because buildbot hasn't been
33
94
# installed yet, or that it wasn't running; just
34
95
# ignore the error.