1
# This file is part of the Juju GUI, which lets users view and manage Juju
2
# environments within a graphical interface (https://launchpad.net/juju-gui).
3
# Copyright (C) 2012-2013 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU Affero General Public License version 3, as published by
7
# the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Affero General Public License for more details.
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
These are actually maintained in python-shelltoolbox. Precise does not have
19
that package, so we need to bootstrap the process by copying the functions
30
def run(*args, **kwargs):
31
"""Run the command with the given arguments.
33
The first argument is the path to the command to run.
34
Subsequent arguments are command-line arguments to be passed.
36
This function accepts all optional keyword arguments accepted by
39
args = [i for i in args if i is not None]
40
pipe = subprocess.PIPE
41
process = subprocess.Popen(
42
args, stdout=kwargs.pop('stdout', pipe),
43
stderr=kwargs.pop('stderr', pipe),
44
close_fds=kwargs.pop('close_fds', True), **kwargs)
45
stdout, stderr = process.communicate()
46
if process.returncode:
47
exception = subprocess.CalledProcessError(
48
process.returncode, repr(args))
49
# The output argument of `CalledProcessError` was introduced in
50
# Python 2.7. Monkey patch the output here to avoid TypeErrors
51
# in older versions of Python, still preserving the output in
53
exception.output = ''.join(filter(None, [stdout, stderr]))
57
def install_extra_repositories(*repositories):
58
"""Install all of the extra repositories and update apt.
60
Given repositories can contain a "{distribution}" placeholder,
61
that will be replaced by current distribution codename.
63
:raises: subprocess.CalledProcessError
65
distribution = run('lsb_release', '-cs').strip()
66
# Starting from Oneiric, `apt-add-repository` is interactive by
67
# default, and requires a "-y" flag to be set.
68
assume_yes = None if distribution == 'lucid' else '-y'
69
for repo in repositories:
70
repository = repo.format(distribution=distribution)
71
run('apt-add-repository', assume_yes, repository)
72
run('apt-get', 'clean')
73
run('apt-get', 'update')
76
install_extra_repositories = shelltoolbox.install_extra_repositories
77
run = shelltoolbox.run