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

Proposed by Francesco Banconi on 2012-03-02
Status: Merged
Merged at revision: 39
Proposed branch: lp:~frankban/charms/oneiric/buildbot-master/add-repositories
Merge into: lp:~yellow/charms/oneiric/buildbot-master/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-master/add-repositories
Reviewer Review Type Date Requested Status
Benji York (community) code 2012-03-02 Approve on 2012-03-02
Review via email: mp+95613@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.
40. By Francesco Banconi on 2012-03-02

Fixed comment.

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-02 10:59:48 +0000
3+++ hooks/install 2012-03-02 17:10:23 +0000
4@@ -8,14 +8,21 @@
5 import subprocess
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@@ -52,12 +59,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