author | ymh <ymh.work@gmail.com> |
Fri, 31 Mar 2017 17:15:17 +0200 | |
changeset 334 | 0ddcaaf893e9 |
parent 244 | 4f07ad576fee |
permissions | -rw-r--r-- |
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
1 |
from distutils.util import strtobool |
193 | 2 |
import imp |
3 |
import os.path |
|
4 |
||
5 |
from fablib import (export_version, do_sync_web, create_config, |
|
6 |
clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv, |
|
7 |
clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp, |
|
60
10e4b6eae0e5
sync script evolution for django-chunked-upload
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
8 |
do_relaunch_server) |
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
9 |
|
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
10 |
import config # @UnusedImport |
60
10e4b6eae0e5
sync script evolution for django-chunked-upload
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
11 |
from fabric.api import task, env |
0 | 12 |
from fabric.colors import green |
193 | 13 |
from fabric.tasks import execute |
14 |
||
15 |
||
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
16 |
def _prep_bool_arg(arg): |
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
17 |
return bool(strtobool(str(arg))) |
0 | 18 |
|
19 |
@task |
|
173 | 20 |
def relaunch_server(do_collectstatic=True, do_syncdb=True, do_check_folder_access=True): |
0 | 21 |
print("Relaunch server") |
173 | 22 |
do_relaunch_server(do_collectstatic, do_syncdb, env.get('check_folder_access',do_check_folder_access)) |
0 | 23 |
|
24 |
@task |
|
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
25 |
def sync_web(version, relaunch=True): |
0 | 26 |
print(green("sync web with version %s" % version)) |
3
800c48d0e3c1
Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents:
1
diff
changeset
|
27 |
export_path = export_version(web=version) |
1 | 28 |
export_path_full = os.path.join(export_path,'web') |
29 |
do_sync_web(version, export_path_full) |
|
30 |
create_config(export_path_full) |
|
0 | 31 |
clean_export_folder(export_path) |
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
32 |
if _prep_bool_arg(relaunch): |
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
33 |
relaunch_server() |
0 | 34 |
|
35 |
@task |
|
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
36 |
def update_lib(version, package, relaunch=True): |
109 | 37 |
print(green("update %s with version %s" % (package,version))) |
3
800c48d0e3c1
Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents:
1
diff
changeset
|
38 |
export_path = export_version(web=version) |
1 | 39 |
export_path_full = os.path.join(export_path,'web') |
40 |
lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib") |
|
0 | 41 |
|
42 |
f, pathname, description = imp.find_module("patch", [lib_path]) |
|
23 | 43 |
imp.load_module("patch", f, pathname, description) |
0 | 44 |
f, pathname, description = imp.find_module("lib_create_env", [lib_path]) |
45 |
lib_create_env = imp.load_module("lib_create_env", f, pathname, description) |
|
46 |
||
23 | 47 |
package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local']) |
0 | 48 |
|
1 | 49 |
sync_install_build(package_path_full) |
0 | 50 |
clean_export_folder(export_path) |
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
51 |
if _prep_bool_arg(relaunch): |
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
52 |
relaunch_server() |
0 | 53 |
|
54 |
@task |
|
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
55 |
def sync_platform(version, relaunch=True): |
23 | 56 |
print(green("sync platform with version web %s" % (version))) |
57 |
export_path = export_version(web=version) |
|
58 |
||
1 | 59 |
export_path_web = os.path.join(export_path,'web') |
23 | 60 |
do_sync_web(version, export_path_web) |
61 |
||
62 |
comp_versions = get_comp_versions_dict(export_path_web) |
|
63 |
||
47 | 64 |
for key in [k for k in env.repos if k != 'web']: |
23 | 65 |
export_path_key = export_version(**{key: comp_versions[key]}) |
66 |
export_path_comp = os.path.join(export_path_key, key) |
|
67 |
do_sync_comp(key, export_path_comp) |
|
68 |
clean_export_folder(export_path_key) |
|
69 |
||
1 | 70 |
create_config(export_path_web) |
0 | 71 |
clean_export_folder(export_path) |
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
72 |
if _prep_bool_arg(relaunch): |
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
73 |
relaunch_server() |
0 | 74 |
|
75 |
@task |
|
193 | 76 |
def create_virtualenv(version, add_dep='no'): |
0 | 77 |
print(green("create virtualenv with version %s" % version)) |
3
800c48d0e3c1
Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents:
1
diff
changeset
|
78 |
export_path = export_version(web=version) |
1 | 79 |
export_path_web = os.path.join(export_path,'web') |
0 | 80 |
venv_remote_export_path = "" |
81 |
try: |
|
1 | 82 |
virtualenv_path = os.path.join(export_path_web, "virtualenv") |
0 | 83 |
|
1 | 84 |
venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv") |
85 |
rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv']) |
|
86 |
do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv']) |
|
193 | 87 |
|
88 |
if add_dep and add_dep.lower()[0] == 'y': |
|
89 |
for sync_name in [key for key in env.repos if key != 'web']: |
|
90 |
execute("sync_"+sync_name, version) |
|
0 | 91 |
finally: |
92 |
clean_export_folder(export_path) |
|
93 |
if venv_remote_export_path: |
|
94 |
clean_rsync_folder(venv_remote_export_path) |
|
1 | 95 |
|
23 | 96 |
|
97 |
for sync_name in [key for key in env.repos if key != 'web']: |
|
98 |
globals()[sync_name] = SyncComp(sync_name) |
|
244
4f07ad576fee
finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents:
193
diff
changeset
|
99 |