|
159
|
1 |
import imp |
|
|
2 |
import os.path |
|
|
3 |
import StringIO |
|
|
4 |
|
|
|
5 |
import config # @UnusedImport |
|
|
6 |
from fablib import (export_version, do_sync_web, create_config, |
|
|
7 |
clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv, |
|
|
8 |
clean_rsync_folder, rsync_export, get_src_version, sync_build, |
|
|
9 |
do_relaunch_server, install_build, do_create_virtualenv_requirement) |
|
|
10 |
from fabric.api import task, env |
|
|
11 |
from fabric.colors import green |
|
|
12 |
|
|
|
13 |
def build_source(version): |
|
|
14 |
print(green("build source with version %s" % version)) |
|
|
15 |
export_path = export_version(iconolab=version) |
|
|
16 |
export_path_full = os.path.join(export_path,'src') |
|
|
17 |
build_src(export_path_full) |
|
|
18 |
(_,version_str) = get_src_version(env.key, src_path) |
|
|
19 |
return os.path.join(src_path,"dist","%s-%s.tar.gz" % (env.key,version_str)) |
|
|
20 |
|
|
|
21 |
@task |
|
|
22 |
def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False): |
|
|
23 |
print("Relaunch server") |
|
|
24 |
do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access)) |
|
|
25 |
|
|
|
26 |
@task |
|
|
27 |
def sync_site(version): |
|
|
28 |
print(green("sync site with version %s" % version)) |
|
|
29 |
build_path = build_source(version) |
|
|
30 |
res_trans = sync_build(build_path) |
|
|
31 |
# untar build |
|
|
32 |
run('tar zxf %s' % res_trans[0]) |
|
|
33 |
# rebuild virtualenv |
|
|
34 |
requirements_path = os.path.join(res_trans[0][0:-7], env.repos[env.key]['requirements']) |
|
|
35 |
do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version']) |
|
|
36 |
# add setting path to virtualenv |
|
|
37 |
ext_path = "import sys; sys.__plen = len(sys.path)\n" |
|
|
38 |
for l in env.remote_path.get('pythonpath', []): |
|
|
39 |
ext_path += l + "\n" |
|
|
40 |
ext_path += "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" |
|
|
41 |
put(StringIO.StringIO(ext_path), os.path.join(env.remote_path['virtualenv'], 'lib/python%s/site-packages/_virtualenv_path_extensions.pth'%env.repos[env.key]['python_version'])) |
|
|
42 |
# install build |
|
|
43 |
install_build(res_trans[0], env.remote_path['virtualenv']) |
|
|
44 |
# remove build + untared folder |
|
|
45 |
run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) |
|
|
46 |
clean_export_folder(export_path) |
|
|
47 |
relaunch_server() |
|
|
48 |
|
|
|
49 |
@task |
|
|
50 |
def create_virtualenv(version): |
|
|
51 |
print(green("create virtualenv with version %s" % version)) |
|
|
52 |
export_path = export_version(web=version) |
|
|
53 |
export_path_web = os.path.join(export_path,'web') |
|
|
54 |
venv_remote_export_path = "" |
|
|
55 |
try: |
|
|
56 |
virtualenv_path = os.path.join(export_path_web, "virtualenv") |
|
|
57 |
|
|
|
58 |
venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv") |
|
|
59 |
rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv']) |
|
|
60 |
do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv']) |
|
|
61 |
finally: |
|
|
62 |
clean_export_folder(export_path) |
|
|
63 |
if venv_remote_export_path: |
|
|
64 |
clean_rsync_folder(venv_remote_export_path) |
|
|
65 |
|
|
|
66 |
if len(env.repos) > 1: |
|
|
67 |
@task |
|
|
68 |
def sync_platform(version): |
|
|
69 |
print(green("sync platform with version web %s" % (version))) |
|
|
70 |
export_path = export_version(web=version) |
|
|
71 |
|
|
|
72 |
export_path_web = os.path.join(export_path,'web') |
|
|
73 |
do_sync_web(version, export_path_web) |
|
|
74 |
|
|
|
75 |
comp_versions = get_comp_versions_dict(export_path_web) |
|
|
76 |
|
|
|
77 |
for key in [k for k in env.repos if k != 'web']: |
|
|
78 |
export_path_key = export_version(**{key: comp_versions[key]}) |
|
|
79 |
export_path_comp = os.path.join(export_path_key, key) |
|
|
80 |
do_sync_comp(key, export_path_comp) |
|
|
81 |
clean_export_folder(export_path_key) |
|
|
82 |
|
|
|
83 |
create_config(export_path_web) |
|
|
84 |
clean_export_folder(export_path) |
|
|
85 |
relaunch_server() |