| author | ymh <ymh.work@gmail.com> |
| Thu, 01 Sep 2016 14:08:20 +0200 | |
| changeset 166 | e9cd38b7cfe0 |
| parent 162 | f014c1593ade |
| child 171 | 9b019ac3b791 |
| permissions | -rw-r--r-- |
| 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, |
|
| 162 | 9 |
do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src) |
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
10 |
from fabric.api import task, env, run, cd, put |
| 159 | 11 |
from fabric.colors import green |
12 |
||
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
13 |
env.use_ssh_config = True |
|
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
14 |
|
| 159 | 15 |
def build_source(version): |
16 |
print(green("build source with version %s" % version)) |
|
17 |
export_path = export_version(iconolab=version) |
|
| 162 | 18 |
export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root']) |
| 159 | 19 |
build_src(export_path_full) |
| 162 | 20 |
(_,version_str) = get_src_version(env.key, export_path_full) |
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
21 |
return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str)) |
| 159 | 22 |
|
23 |
@task |
|
24 |
def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False): |
|
25 |
print("Relaunch server") |
|
26 |
do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access)) |
|
27 |
||
28 |
@task |
|
29 |
def sync_site(version): |
|
30 |
print(green("sync site with version %s" % version)) |
|
31 |
build_path = build_source(version) |
|
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
32 |
run('mkdir -p "%s"' % env.remote_path['build_export']) |
| 159 | 33 |
res_trans = sync_build(build_path) |
34 |
# untar build |
|
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
35 |
with cd(env.remote_path['build_export']): |
|
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
36 |
run('tar zxf %s' % res_trans[0]) |
| 159 | 37 |
# rebuild virtualenv |
38 |
requirements_path = os.path.join(res_trans[0][0:-7], env.repos[env.key]['requirements']) |
|
39 |
do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version']) |
|
40 |
# add setting path to virtualenv |
|
41 |
ext_path = "import sys; sys.__plen = len(sys.path)\n" |
|
42 |
for l in env.remote_path.get('pythonpath', []): |
|
43 |
ext_path += l + "\n" |
|
44 |
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)" |
|
45 |
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'])) |
|
46 |
# install build |
|
47 |
install_build(res_trans[0], env.remote_path['virtualenv']) |
|
48 |
# remove build + untared folder |
|
49 |
run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) |
|
50 |
clean_export_folder(export_path) |
|
51 |
relaunch_server() |
|
52 |
||
53 |
@task |
|
54 |
def create_virtualenv(version): |
|
55 |
print(green("create virtualenv with version %s" % version)) |
|
56 |
export_path = export_version(web=version) |
|
57 |
export_path_web = os.path.join(export_path,'web') |
|
58 |
venv_remote_export_path = "" |
|
59 |
try: |
|
60 |
virtualenv_path = os.path.join(export_path_web, "virtualenv") |
|
61 |
||
62 |
venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv") |
|
63 |
rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv']) |
|
64 |
do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv']) |
|
65 |
finally: |
|
66 |
clean_export_folder(export_path) |
|
67 |
if venv_remote_export_path: |
|
68 |
clean_rsync_folder(venv_remote_export_path) |
|
69 |
||
70 |
if len(env.repos) > 1: |
|
71 |
@task |
|
72 |
def sync_platform(version): |
|
73 |
print(green("sync platform with version web %s" % (version))) |
|
74 |
export_path = export_version(web=version) |
|
75 |
||
76 |
export_path_web = os.path.join(export_path,'web') |
|
77 |
do_sync_web(version, export_path_web) |
|
78 |
||
79 |
comp_versions = get_comp_versions_dict(export_path_web) |
|
80 |
||
81 |
for key in [k for k in env.repos if k != 'web']: |
|
82 |
export_path_key = export_version(**{key: comp_versions[key]}) |
|
83 |
export_path_comp = os.path.join(export_path_key, key) |
|
84 |
do_sync_comp(key, export_path_comp) |
|
85 |
clean_export_folder(export_path_key) |
|
86 |
||
87 |
create_config(export_path_web) |
|
88 |
clean_export_folder(export_path) |
|
89 |
relaunch_server() |