author | ymh <ymh.work@gmail.com> |
Tue, 04 Dec 2012 00:17:10 +0100 | |
changeset 23 | 7df43b86c425 |
parent 11 | fc7cc9667de1 |
child 24 | 6b79d5424407 |
permissions | -rw-r--r-- |
23 | 1 |
from fabric.api import task, env, sudo |
0 | 2 |
from fabric.colors import green |
23 | 3 |
from fabric.tasks import Task |
4 |
from ldt_fablib import (check_folder_access, syncdb, collectstatic, |
|
5 |
export_version, do_sync_web, create_config, clean_export_folder, do_sync_comp, |
|
6 |
sync_install_build, do_create_virtualenv, clean_rsync_folder, rsync_export, |
|
7 |
get_comp_versions_dict) |
|
0 | 8 |
import imp |
23 | 9 |
import os.path |
0 | 10 |
|
11 |
@task |
|
11 | 12 |
def relaunch_server(do_collectstatic=True, do_syncdb=True): |
0 | 13 |
print("Relaunch server") |
14 |
check_folder_access() |
|
11 | 15 |
if do_syncdb: |
16 |
syncdb(env.remote_path['src'], env.remote_path['virtualenv']) |
|
0 | 17 |
if do_collectstatic: |
7 | 18 |
collectstatic(env.remote_path['src'], env.remote_path['virtualenv'], env.platform_web_module) |
0 | 19 |
sudo(env.web_relaunch_cmd, shell=False) |
20 |
||
21 |
@task |
|
22 |
def sync_web(version): |
|
23 |
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
|
24 |
export_path = export_version(web=version) |
1 | 25 |
export_path_full = os.path.join(export_path,'web') |
26 |
do_sync_web(version, export_path_full) |
|
27 |
create_config(export_path_full) |
|
0 | 28 |
clean_export_folder(export_path) |
29 |
relaunch_server() |
|
30 |
||
31 |
@task |
|
32 |
def update_lib(version, package): |
|
33 |
print(green("update ldt 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
|
34 |
export_path = export_version(web=version) |
1 | 35 |
export_path_full = os.path.join(export_path,'web') |
36 |
lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib") |
|
0 | 37 |
|
38 |
f, pathname, description = imp.find_module("patch", [lib_path]) |
|
23 | 39 |
imp.load_module("patch", f, pathname, description) |
0 | 40 |
f, pathname, description = imp.find_module("lib_create_env", [lib_path]) |
41 |
lib_create_env = imp.load_module("lib_create_env", f, pathname, description) |
|
42 |
||
23 | 43 |
package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local']) |
0 | 44 |
|
1 | 45 |
sync_install_build(package_path_full) |
0 | 46 |
clean_export_folder(export_path) |
47 |
relaunch_server() |
|
48 |
||
49 |
@task |
|
23 | 50 |
def sync_platform(version): |
51 |
print(green("sync platform with version web %s" % (version))) |
|
52 |
export_path = export_version(web=version) |
|
53 |
||
1 | 54 |
export_path_web = os.path.join(export_path,'web') |
23 | 55 |
do_sync_web(version, export_path_web) |
56 |
||
57 |
comp_versions = get_comp_versions_dict(export_path_web) |
|
58 |
||
59 |
for key in [k for k in env.repos if key != 'web']: |
|
60 |
export_path_key = export_version(**{key: comp_versions[key]}) |
|
61 |
export_path_comp = os.path.join(export_path_key, key) |
|
62 |
do_sync_comp(key, export_path_comp) |
|
63 |
clean_export_folder(export_path_key) |
|
64 |
||
1 | 65 |
create_config(export_path_web) |
0 | 66 |
clean_export_folder(export_path) |
67 |
relaunch_server() |
|
68 |
||
69 |
@task |
|
70 |
def create_virtualenv(version): |
|
71 |
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
|
72 |
export_path = export_version(web=version) |
1 | 73 |
export_path_web = os.path.join(export_path,'web') |
0 | 74 |
venv_remote_export_path = "" |
75 |
try: |
|
1 | 76 |
virtualenv_path = os.path.join(export_path_web, "virtualenv") |
0 | 77 |
|
1 | 78 |
venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv") |
79 |
rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv']) |
|
80 |
do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv']) |
|
0 | 81 |
finally: |
82 |
clean_export_folder(export_path) |
|
83 |
if venv_remote_export_path: |
|
84 |
clean_rsync_folder(venv_remote_export_path) |
|
1 | 85 |
|
23 | 86 |
class SyncComp(Task): |
87 |
||
88 |
def __init__(self, key): |
|
89 |
self.key = key |
|
1 | 90 |
|
23 | 91 |
def __get_name(self): |
92 |
return "sync_" + self.key |
|
93 |
||
94 |
name = property(__get_name) |
|
95 |
||
96 |
def run(self, version): |
|
97 |
print(green("sync ldt with version %s" % version)) |
|
98 |
export_path_web = export_version(web=version) |
|
99 |
export_path_web_full = os.path.join(export_path_web,'web') |
|
100 |
comp_versions = get_comp_versions_dict(export_path_web_full) |
|
101 |
||
102 |
export_path = export_version(**{self.key:comp_versions[self.key]}) |
|
103 |
export_path_full = os.path.join(export_path,self.key) |
|
104 |
do_sync_comp(self.key, export_path_full) |
|
105 |
clean_export_folder(export_path) |
|
106 |
clean_export_folder(export_path_web) |
|
107 |
||
108 |
relaunch_server() |
|
109 |
||
110 |
for sync_name in [key for key in env.repos if key != 'web']: |
|
111 |
globals()[sync_name] = SyncComp(sync_name) |