~charmers/charms/precise/buildbot-master/trunk

« back to all changes in this revision

Viewing changes to hooks/install

  • Committer: Francesco Banconi
  • Date: 2012-02-07 14:37:13 UTC
  • mfrom: (11.1.8 dynamic-relationship)
  • Revision ID: francesco.banconi@canonical.com-20120207143713-7ycviq0xpp8roffy
Merged branch dynamic-relationship and added cleanup fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
from helpers import command, get_config, run, log
4
 
from subprocess import CalledProcessError
 
3
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
4
# GNU Affero General Public License version 3 (see the file LICENSE).
 
5
 
5
6
import os
6
7
import shutil
7
 
 
8
 
log = command('juju-log')
9
 
 
10
 
# Log the fact that we're about to begin the install step.
11
 
log('--> install')
12
 
 
13
 
config = get_config()
14
 
log("config:")
15
 
log(str(config))
16
 
 
17
 
buildbot_dir =  config['installdir']
18
 
run('apt-get', 'install', '-y', 'sharutils', 'bzr')
19
 
 
20
 
# Install the extra repository
21
 
# Install the initially configured version of buildbot.
22
 
 
23
 
# Since we may be installing into a pre-existing service, ensure the
24
 
# buildbot directory is removed.
25
 
if os.path.exists(buildbot_dir):
26
 
    try:
27
 
        run('buildbot', 'stop', buildbot_dir)
28
 
    except CalledProcessError:
29
 
        # It probably wasn't running; just ignore the error.
30
 
        pass
31
 
    shutil.rmtree(buildbot_dir)
32
 
 
33
 
# Log the fact that the install step is done.
34
 
log('<-- install')
 
8
from subprocess import CalledProcessError
 
9
 
 
10
from helpers import (
 
11
    apt_get_install,
 
12
    get_config,
 
13
    log,
 
14
    run,
 
15
    )
 
16
from local import (
 
17
    config_json,
 
18
    slave_json,
 
19
    )
 
20
 
 
21
 
 
22
def bootstrap(buildbot_dir):
 
23
    apt_get_install('bzr')
 
24
    # Since we may be installing into a pre-existing service, ensure the
 
25
    # buildbot directory is removed.
 
26
    if os.path.exists(buildbot_dir):
 
27
        try:
 
28
            run('buildbot', 'stop', buildbot_dir)
 
29
        except (CalledProcessError, OSError):
 
30
            # This usually happens because buildbot hasn't been
 
31
            # installed yet, or that it wasn't running; just ignore the
 
32
            # error.
 
33
            pass
 
34
        shutil.rmtree(buildbot_dir)
 
35
    # Initialize the cached config so that old configs don't hang around
 
36
    # after the service is torn down.
 
37
    config_json.set({})
 
38
    slave_json.set({})
 
39
 
 
40
 
 
41
def main():
 
42
    config = get_config()
 
43
    log("config:")
 
44
    log(str(config))
 
45
    bootstrap(config['installdir'])
 
46
 
 
47
 
 
48
if __name__ == '__main__':
 
49
    log('INSTALL HOOK:')
 
50
    main()