← Back to team overview

yellow team mailing list archive

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

 

Francesco Banconi has proposed merging lp:~frankban/charms/oneiric/buildbot-slave/add-repositories into lp:~yellow/charms/oneiric/buildbot-slave/trunk.

Requested reviews:
  Launchpad Yellow Squad (yellow)

For more details, see:
https://code.launchpad.net/~frankban/charms/oneiric/buildbot-slave/add-repositories/+merge/95612

== Changes ==

- Fixed install_extra_repository
- Using the version of `run` helper (ported from python-shell-toolbox)
-- 
https://code.launchpad.net/~frankban/charms/oneiric/buildbot-slave/add-repositories/+merge/95612
Your team Launchpad Yellow Squad is requested to review the proposed merge of lp:~frankban/charms/oneiric/buildbot-slave/add-repositories into lp:~yellow/charms/oneiric/buildbot-slave/trunk.
=== modified file 'hooks/install'
--- hooks/install	2012-03-01 18:24:15 +0000
+++ hooks/install	2012-03-02 16:37:21 +0000
@@ -10,14 +10,21 @@
 import tempfile
 
 
-def run(*args):
+def run(*args, **kwargs):
     """Run the command with the given arguments.
 
-    The first argument is the path to the command to run, subsequent arguments
-    are command-line arguments to be passed.
+    The first argument is the path to the command to run.
+    Subsequent arguments are command-line arguments to be passed.
+
+    This function accepts all optional keyword arguments accepted by
+    `subprocess.Popen`.
     """
-    process = subprocess.Popen(args, stdout=subprocess.PIPE,
-        stderr=subprocess.PIPE, close_fds=True)
+    args = [i for i in args if i is not None]
+    pipe = subprocess.PIPE
+    process = subprocess.Popen(
+        args, stdout=kwargs.pop('stdout', pipe),
+        stderr=kwargs.pop('stderr', pipe),
+        close_fds=kwargs.pop('close_fds', True), **kwargs)
     stdout, stderr = process.communicate()
     if process.returncode:
         raise subprocess.CalledProcessError(
@@ -55,12 +62,16 @@
 
 
 def install_extra_repository(extra_repository):
+    distribution = run('lsb_release', '-cs').strip()
+    # Starting from Oneiric, the `apt-add-repository` is interactive by
+    # default, and requires a "-y" flag to be set.
+    assume_yes = None if distribution == 'lucid' else '-y'
     try:
-        run('apt-add-repository', extra_repository)
+        run('apt-add-repository', assume_yes, extra_repository)
         run('apt-get', 'update')
     except subprocess.CalledProcessError as e:
         log('Error adding repository: ' + extra_repository)
-        log(e)
+        log(str(e))
         raise
 
 


Follow ups