1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#!/usr/bin/env python2
# -*- python -*-
# This file is part of the Juju GUI, which lets users view and manage Juju
# environments within a graphical interface (https://launchpad.net/juju-gui).
# Copyright (C) 2012-2013 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License version 3, as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import errno
import os
from shelltoolbox import (
apt_get_install,
run,
)
# Python dependencies must be installed here so that the charm can import and
# use required libraries.
PYTHON_DEPENDENCIES = (
'python-apt', 'python-launchpadlib', 'python-tempita', 'python-yaml')
run('juju-log', '--', 'Installing base Python dependencies: {}.'.format(
', '.join(PYTHON_DEPENDENCIES)))
apt_get_install(*PYTHON_DEPENDENCIES)
# The charmhelpers module depends on python-yaml and must be imported only
# after the installation of the Python dependencies above.
from charmhelpers import (
get_config,
log,
)
from utils import (
config_json,
log_hook,
)
from backend import Backend
def main():
# Run pre-install tasks, if available. Please do not rely on the
# exec.d interface without conferring with the Juju GUI team: it may
# change after upcoming discussion with Canonical IS.
if os.path.isdir('exec.d'):
dirnames = os.listdir('exec.d')
dirnames.sort()
for module in dirnames:
filename = os.path.join('exec.d', module, 'charm-pre-install')
try:
run(filename)
except OSError, e:
# If the exec.d file does not exist or is not runnable or
# is not a directory, assume we can recover. Log the problem
# and proceed. Note that Juju Core has a special need of
# errno.ENOTDIR because it apparently adds a ".empty" file in
# empty charm directories, so trying to run
# ./exec.d/.empty/charm-pre-install will trigger that error.
if e.errno in (errno.ENOENT, errno.EACCES, errno.ENOTDIR):
log('{}: {}'.format(e.strerror, filename))
else:
raise
config = get_config()
backend = Backend(config)
backend.install()
# Store current configuration.
config_json.set(config)
if __name__ == '__main__':
with log_hook():
main()
|