~brianlbaird/charms/trusty/mme/trunk

« back to all changes in this revision

Viewing changes to lib/charms/bootstrap.py

  • Committer: brianlbaird at gmail
  • Date: 2016-02-05 22:54:17 UTC
  • Revision ID: brianlbaird@gmail.com-20160205225417-8f89hq9ij9p2fhsy
update mme name in docker-compose.yaml

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import sys
 
3
from glob import glob
 
4
from subprocess import check_call
 
5
 
 
6
 
 
7
def bootstrap_charm_deps():
 
8
    if os.path.exists('wheelhouse/.bootstrapped'):
 
9
        return
 
10
    # bootstrap wheelhouse
 
11
    if os.path.exists('wheelhouse'):
 
12
        apt_install(['python3-pip', 'python3-yaml'])
 
13
        # install packages defined in layer.yaml
 
14
        install_charm_deps()
 
15
        # need newer pip, to fix spurious Double Requirement error https://github.com/pypa/pip/issues/56
 
16
        check_call(['pip3', 'install', '-U', '--no-index', '-f', 'wheelhouse', 'pip'])
 
17
        # install the rest of the wheelhouse deps
 
18
        check_call(['pip3', 'install', '-U', '--no-index', '-f', 'wheelhouse'] + glob('wheelhouse/*'))
 
19
        # flag us as having already bootstrapped so we don't do it again
 
20
        open('wheelhouse/.bootstrapped', 'w').close()
 
21
        # Ensure that the newly bootstrapped libs are available.
 
22
        # Note: this only seems to be an issue with namespace packages.
 
23
        # Non-namespace-package libs (e.g., charmhelpers) are available
 
24
        # without having to reload the interpreter. :/
 
25
        os.execl(sys.argv[0], sys.argv[0])
 
26
 
 
27
 
 
28
def install_charm_deps():
 
29
    from charms import layer
 
30
 
 
31
    cfg = layer.options('basic')
 
32
    apt_install(cfg.get('packages', []))
 
33
 
 
34
 
 
35
def apt_install(packages):
 
36
    if isinstance(packages, (str, bytes)):
 
37
        packages = [packages]
 
38
 
 
39
    env = os.environ.copy()
 
40
 
 
41
    if 'DEBIAN_FRONTEND' not in env:
 
42
        env['DEBIAN_FRONTEND'] = 'noninteractive'
 
43
 
 
44
    cmd = ['apt-get',
 
45
           '--option=Dpkg::Options::=--force-confold',
 
46
           '--assume-yes',
 
47
           'install']
 
48
    check_call(cmd + packages, env=env)