Merge lp:~frankban/charms/oneiric/buildbot-slave/add-repositories into lp:~yellow/charms/oneiric/buildbot-slave/trunk

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 21
Proposed branch: lp:~frankban/charms/oneiric/buildbot-slave/add-repositories
Merge into: lp:~yellow/charms/oneiric/buildbot-slave/trunk
Diff against target: 47 lines (+18/-7)
1 file modified
hooks/install (+18/-7)
To merge this branch: bzr merge lp:~frankban/charms/oneiric/buildbot-slave/add-repositories
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+95612@code.launchpad.net

Description of the change

== Changes ==

- Fixed install_extra_repository
- Using the version of `run` helper (ported from python-shell-toolbox)

To post a comment you must log in.
22. By Francesco Banconi

Fixed comment.

Revision history for this message
Benji York (benji) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/install'
2--- hooks/install 2012-03-01 18:24:15 +0000
3+++ hooks/install 2012-03-02 17:10:24 +0000
4@@ -10,14 +10,21 @@
5 import tempfile
6
7
8-def run(*args):
9+def run(*args, **kwargs):
10 """Run the command with the given arguments.
11
12- The first argument is the path to the command to run, subsequent arguments
13- are command-line arguments to be passed.
14+ The first argument is the path to the command to run.
15+ Subsequent arguments are command-line arguments to be passed.
16+
17+ This function accepts all optional keyword arguments accepted by
18+ `subprocess.Popen`.
19 """
20- process = subprocess.Popen(args, stdout=subprocess.PIPE,
21- stderr=subprocess.PIPE, close_fds=True)
22+ args = [i for i in args if i is not None]
23+ pipe = subprocess.PIPE
24+ process = subprocess.Popen(
25+ args, stdout=kwargs.pop('stdout', pipe),
26+ stderr=kwargs.pop('stderr', pipe),
27+ close_fds=kwargs.pop('close_fds', True), **kwargs)
28 stdout, stderr = process.communicate()
29 if process.returncode:
30 raise subprocess.CalledProcessError(
31@@ -55,12 +62,16 @@
32
33
34 def install_extra_repository(extra_repository):
35+ distribution = run('lsb_release', '-cs').strip()
36+ # Starting from Oneiric, `apt-add-repository` is interactive by
37+ # default, and requires a "-y" flag to be set.
38+ assume_yes = None if distribution == 'lucid' else '-y'
39 try:
40- run('apt-add-repository', extra_repository)
41+ run('apt-add-repository', assume_yes, extra_repository)
42 run('apt-get', 'update')
43 except subprocess.CalledProcessError as e:
44 log('Error adding repository: ' + extra_repository)
45- log(e)
46+ log(str(e))
47 raise
48
49

Subscribers

People subscribed via source and target branches