~arosales/charms/precise/buildbot-master/icon-categories-add

« back to all changes in this revision

Viewing changes to hooks/install

  • Committer: Brad Crittenden
  • Date: 2012-03-01 14:07:49 UTC
  • mfrom: (36.1.2 bbm-pst)
  • Revision ID: bac@canonical.com-20120301140749-o1pagcjt7lt4i9ej
[r=gmb] Migrate methods from Juju-specific helpers.py module to python-shell-toolbox and handle all of the installation issues that raises.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import os
7
7
import shutil
8
 
from subprocess import CalledProcessError
9
 
 
 
8
import subprocess
 
9
 
 
10
 
 
11
def run(*args):
 
12
    """Run the command with the given arguments.
 
13
 
 
14
    The first argument is the path to the command to run, subsequent arguments
 
15
    are command-line arguments to be passed.
 
16
    """
 
17
    process = subprocess.Popen(args, stdout=subprocess.PIPE,
 
18
        stderr=subprocess.PIPE, close_fds=True)
 
19
    stdout, stderr = process.communicate()
 
20
    if process.returncode:
 
21
        raise subprocess.CalledProcessError(
 
22
            process.returncode, repr(args), output=stdout+stderr)
 
23
    return stdout
 
24
 
 
25
 
 
26
def command(*base_args):
 
27
    """Return a callable that will run the given command with any arguments.
 
28
 
 
29
    The first argument is the path to the command to run, subsequent arguments
 
30
    are command-line arguments to "bake into" the returned callable.
 
31
 
 
32
    The callable runs the given executable and also takes arguments that will
 
33
    be appeneded to the "baked in" arguments.
 
34
 
 
35
    For example, this code will list a file named "foo" (if it exists):
 
36
 
 
37
        ls_foo = command('/bin/ls', 'foo')
 
38
        ls_foo()
 
39
 
 
40
    While this invocation will list "foo" and "bar" (assuming they exist):
 
41
 
 
42
        ls_foo('bar')
 
43
    """
 
44
    def callable_command(*args):
 
45
        all_args = base_args + args
 
46
        return run(*all_args)
 
47
 
 
48
    return callable_command
 
49
 
 
50
 
 
51
log = command('juju-log')
 
52
 
 
53
 
 
54
def install_extra_repository(extra_repository):
 
55
    try:
 
56
        run('apt-add-repository', extra_repository)
 
57
        run('apt-get', 'update')
 
58
    except subprocess.CalledProcessError as e:
 
59
        log('Error adding repository: ' + extra_repository)
 
60
        log(e)
 
61
        raise
 
62
 
 
63
 
 
64
def install_packages():
 
65
    apt_get_install = command('apt-get', 'install', '-y', '--force-yes')
 
66
    apt_get_install('bzr', 'python-boto')
 
67
    install_extra_repository('ppa:yellow/ppa')
 
68
    apt_get_install('python-shell-toolbox')
 
69
 
 
70
 
 
71
install_packages()
 
72
 
 
73
# These modules depend on shelltoolbox being installed so they must not be
 
74
# imported until that package is available.
10
75
from helpers import (
11
 
    apt_get_install,
12
76
    get_config,
13
 
    log,
14
77
    log_entry,
15
78
    log_exit,
16
 
    run,
17
79
    )
18
80
from local import (
19
81
    config_json,
22
84
 
23
85
 
24
86
def cleanup(buildbot_dir):
25
 
    apt_get_install('bzr', 'python-boto')
26
87
    # Since we may be installing into a pre-existing service, ensure the
27
88
    # buildbot directory is removed.
28
89
    if os.path.exists(buildbot_dir):
29
90
        try:
30
91
            run('buildbot', 'stop', buildbot_dir)
31
 
        except (CalledProcessError, OSError):
 
92
        except (subprocess.CalledProcessError, OSError):
32
93
            # This usually happens because buildbot hasn't been
33
94
            # installed yet, or that it wasn't running; just
34
95
            # ignore the error.
52
113
 
53
114
 
54
115
if __name__ == '__main__':
 
116
 
55
117
    log_entry()
56
118
    try:
57
119
        main()