| author | ymh <ymh.work@gmail.com> |
| Thu, 12 Oct 2017 17:33:07 +0200 | |
| changeset 530 | 9ee6eeb39779 |
| parent 174 | b91ae400f66d |
| 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 |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
23 |
def do_create_virtualenv(remote_build_folder): |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
24 |
requirements_path = os.path.join(remote_build_folder, env.repos[env.key]['requirements']) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
25 |
do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version']) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
26 |
# add setting path to virtualenv |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
27 |
ext_path = "import sys; sys.__plen = len(sys.path)\n" |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
28 |
for l in env.remote_path.get('pythonpath', []): |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
29 |
ext_path += l + "\n" |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
30 |
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)" |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
31 |
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'])) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
32 |
|
| 159 | 33 |
@task |
34 |
def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False): |
|
35 |
print("Relaunch server") |
|
36 |
do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access)) |
|
37 |
||
38 |
@task |
|
39 |
def sync_site(version): |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
40 |
print(green("sync site and rebuild virtualenv with version %s" % version)) |
| 159 | 41 |
build_path = build_source(version) |
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
42 |
run('mkdir -p "%s"' % env.remote_path['build_export']) |
| 159 | 43 |
res_trans = sync_build(build_path) |
44 |
# untar build |
|
|
166
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
45 |
with cd(env.remote_path['build_export']): |
|
e9cd38b7cfe0
improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents:
162
diff
changeset
|
46 |
run('tar zxf %s' % res_trans[0]) |
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
47 |
|
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
48 |
do_create_virtualenv(res_trans[0][0:-7]) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
49 |
|
| 159 | 50 |
# install build |
51 |
install_build(res_trans[0], env.remote_path['virtualenv']) |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
52 |
|
| 159 | 53 |
# remove build + untared folder |
54 |
run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) |
|
| 171 | 55 |
clean_export_folder(env.remote_path['build_export']) |
| 159 | 56 |
relaunch_server() |
57 |
||
58 |
@task |
|
59 |
def create_virtualenv(version): |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
60 |
build_path = build_source(version) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
61 |
run('mkdir -p "%s"' % env.remote_path['build_export']) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
62 |
res_trans = sync_build(build_path) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
63 |
# untar build |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
64 |
with cd(env.remote_path['build_export']): |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
65 |
run('tar zxf %s' % res_trans[0]) |
| 159 | 66 |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
67 |
do_create_virtualenv(res_trans[0][0:-7]) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
68 |
|
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
69 |
run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
70 |
clean_export_folder(env.remote_path['build_export']) |
| 159 | 71 |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
72 |
@task |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
73 |
def sync_site_module(version): |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
74 |
print(green("sync site with version %s" % version)) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
75 |
build_path = build_source(version) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
76 |
run('mkdir -p "%s"' % env.remote_path['build_export']) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
77 |
res_trans = sync_build(build_path) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
78 |
# install build |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
79 |
install_build(res_trans[0], env.remote_path['virtualenv'], env.platform_web_module) |
| 159 | 80 |
|
|
174
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
81 |
# remove build + untared folder |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
82 |
run('rm -fr "%s"' % (res_trans[0])) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
83 |
clean_export_folder(env.remote_path['build_export']) |
|
b91ae400f66d
clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents:
171
diff
changeset
|
84 |
relaunch_server() |