← Back to team overview

yellow team mailing list archive

[Merge] lp:~gary/charms/precise/juju-gui/run-without-ppa into lp:~juju-gui/charms/precise/juju-gui/trunk

 

Gary Poster has proposed merging lp:~gary/charms/precise/juju-gui/run-without-ppa into lp:~juju-gui/charms/precise/juju-gui/trunk.

Requested reviews:
  Juju GUI Hackers (juju-gui)

For more details, see:
https://code.launchpad.net/~gary/charms/precise/juju-gui/run-without-ppa/+merge/142568

Make charm work without environment Juju PPA

As discovered by therve and myself, the charm does not work if "juju-origin: ppa" is not in your environments.yaml for the given Juju environment.  These changes work around the problem.

https://codereview.appspot.com/7073051/

-- 
https://code.launchpad.net/~gary/charms/precise/juju-gui/run-without-ppa/+merge/142568
Your team Juju GUI Hackers is requested to review the proposed merge of lp:~gary/charms/precise/juju-gui/run-without-ppa into lp:~juju-gui/charms/precise/juju-gui/trunk.
=== added file 'hooks/bootstrap_utils.py'
--- hooks/bootstrap_utils.py	1970-01-01 00:00:00 +0000
+++ hooks/bootstrap_utils.py	2013-01-09 18:21:20 +0000
@@ -0,0 +1,54 @@
+# These are actually maintained in python-shelltoolbox.  Precise does not have
+# that package, so we need to bootstrap the process by copying the functions
+# we need here.
+
+import subprocess
+
+try:
+    import shelltoolbox
+except ImportError:
+    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.
+
+        This function accepts all optional keyword arguments accepted by
+        `subprocess.Popen`.
+        """
+        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:
+            exception = subprocess.CalledProcessError(
+                process.returncode, repr(args))
+            # The output argument of `CalledProcessError` was introduced in Python
+            # 2.7. Monkey patch the output here to avoid TypeErrors in older
+            # versions of Python, still preserving the output in Python 2.7.
+            exception.output = ''.join(filter(None, [stdout, stderr]))
+            raise exception
+        return stdout
+
+    def install_extra_repositories(*repositories):
+        """Install all of the extra repositories and update apt.
+
+        Given repositories can contain a "{distribution}" placeholder, that will
+        be replaced by current distribution codename.
+
+        :raises: subprocess.CalledProcessError
+        """
+        distribution = run('lsb_release', '-cs').strip()
+        # Starting from Oneiric, `apt-add-repository` is interactive by
+        # default, and requires a "-y" flag to be set.
+        assume_yes = None if distribution == 'lucid' else '-y'
+        for repo in repositories:
+            repository = repo.format(distribution=distribution)
+            run('apt-add-repository', assume_yes, repository)
+        run('apt-get', 'clean')
+        run('apt-get', 'update')
+else:
+    install_extra_repositories = shelltoolbox.install_extra_repositories

=== modified file 'hooks/install'
--- hooks/install	2012-12-21 15:09:47 +0000
+++ hooks/install	2013-01-09 18:21:20 +0000
@@ -6,6 +6,14 @@
     check_call,
 )
 
+# If the user's environment has "juju-origin: ppa" set, they will
+# automatically have access to python-charmhelpers and python-shelltoolbox.
+# However, we want to support environments that use the non-PPA environment as
+# well.  To do so, we need to install the Juju PPA, which we will do with a
+# couple of functions that are actually maintained in python-shelltoolbox.
+import bootstrap_utils
+bootstrap_utils.install_extra_repositories('ppa:juju/pkgs')
+
 # python-shelltoolbox is installed as a dependency of python-charmhelpers.
 check_call(['apt-get', 'install', '-y', 'python-charmhelpers'])
 

=== modified file 'revision'
--- revision	2013-01-03 20:16:28 +0000
+++ revision	2013-01-09 18:21:20 +0000
@@ -1,1 +1,1 @@
-18
+19


Follow ups