4
from datetime import datetime
5
from base64 import b64decode
8
from lib.charmhelpers.core.hookenv import config
11
charm_dir = os.path.abspath(
12
os.path.join(os.path.dirname(__file__), os.pardir)
16
def install_apt_packages():
18
Install both core and extra apt packages
21
install(config('core_packages').split())
22
install(config('extra_packages').split())
25
def extract_app_files():
27
Extract the app zip file
28
into an install directory (specified in config)
31
app_tgz_path = get_app_tgz()
33
install_dir = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
34
install_path = os.path.join(config('install_path'), install_dir)
36
# Extract files into install dir
39
directory=install_path,
40
strip=1, z=True, x=True
46
def set_current(app_path):
48
Set an app directory to the currently live app
49
by creating a symlink as specified in config
52
current_link_path = os.path.join(
53
config('install_path'),
54
config('live_symlink_name')
57
sh.rm(current_link_path, force=True)
58
sh.ln(app_path, current_link_path, symbolic=True)
63
Get the app tar.gz file from the config (if specified)
64
and save it in the cache directory
68
app_tgz_path = os.path.join(cache_dir(), 'project.tgz')
69
b64_tgz = config('app_package')
72
tgz_contents = b64decode()
74
with open(app_tgz_path, 'w') as tgz_file:
75
tgz_file.write(tgz_contents)
80
def install_dependencies(app_path):
82
Install pip and gem dependencies
86
pip_dependencies_path =
89
def install(packages):
91
Install a list of packages
92
if the list contains any
96
sh.apt_get.install(packages, y=True)
101
Create the cache directory, if it doesn't exist
105
cache_dir = os.path.join(charm_dir, 'cache')
106
sh.mv(cache_dir, p=True)