20 if os.path.isdir(path): |
20 if os.path.isdir(path): |
21 shutil.rmtree(path, ignore_errors=True) |
21 shutil.rmtree(path, ignore_errors=True) |
22 |
22 |
23 def do_export_version(path, version): |
23 def do_export_version(path, version): |
24 print("Export version %s"%str(version)) |
24 print("Export version %s"%str(version)) |
25 |
25 |
26 #hgui = ui.ui() |
|
27 #repo = hg.repository(hgui, cmdutil.findrepo(os.getcwd())) |
|
28 #commands.archive(hgui, repo, path, rev=str(version)) |
|
29 |
|
30 local("hg archive -r \'%s\' \"%s\"" % (str(version),path)) |
26 local("hg archive -r \'%s\' \"%s\"" % (str(version),path)) |
31 print("Export version %s done"%str(version)) |
27 print("Export version %s done"%str(version)) |
|
28 |
|
29 |
|
30 def get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, settings_key): |
|
31 activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
|
32 res = "" |
|
33 with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
|
34 tempfilepath = run("mktemp ldtplatform.XXXXXX") |
|
35 with settings(warn_only=True): |
|
36 run("echo \"import os\" > %s" % (tempfilepath)) |
|
37 map(lambda str: run("echo \"%s\" >> %s" % (str, tempfilepath)), |
|
38 ["os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s.settings')" % (platform_web_module), |
|
39 "from django.conf import settings", |
|
40 "print settings.%s" % (settings_key)]) |
|
41 res = run("python < %s" % (tempfilepath)) |
|
42 run("rm -f \"%s\"" % (tempfilepath)) |
|
43 return res |
|
44 |
|
45 |
32 |
46 |
33 def rsync_export(path, remotepath, filters): |
47 def rsync_export(path, remotepath, filters): |
34 print("Rsync %s to %s",(path,remotepath)) |
48 print("Rsync %s to %s",(path,remotepath)) |
35 |
49 |
36 if filters: |
50 if filters: |
96 activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
110 activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
97 |
111 |
98 with prefix("source %s" % activate_path): |
112 with prefix("source %s" % activate_path): |
99 run("pip install \"%s\"" % remotepath) |
113 run("pip install \"%s\"" % remotepath) |
100 |
114 |
101 def collectstatic(remotepath, remotevirtualenvpath): |
115 def collectstatic(remotepath, remotevirtualenvpath, platform_web_module): |
102 print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath)) |
116 print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath)) |
|
117 remotestaticsitepath = get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, "STATIC_ROOT") |
103 activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
118 activate_path = os.path.join(remotevirtualenvpath, "bin/activate") |
104 with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
119 with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): |
105 run("python manage.py collectstatic -c --noinput") |
120 #remocve old files optio -c of collect static fail ! |
|
121 run("rm -fr \"%s\"" % (remotestaticsitepath)) |
|
122 run("python manage.py collectstatic --noinput") |
106 |
123 |
107 def create_config(export_path): |
124 def create_config(export_path): |
108 print("Create config from %s" % (export_path,)) |
125 print("Create config from %s" % (export_path,)) |
109 remotepath = env.remote_web_path |
126 remotepath = env.remote_web_path |
110 remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py") |
127 remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py") |
195 with settings(warn_only=True): |
212 with settings(warn_only=True): |
196 if not exists(folder_path): |
213 if not exists(folder_path): |
197 run("mkdir -p \"%s\"" % folder_path) |
214 run("mkdir -p \"%s\"" % folder_path) |
198 run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path)) |
215 run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path)) |
199 run("chmod -R -c g+w \"%s\"" % folder_path) |
216 run("chmod -R -c g+w \"%s\"" % folder_path) |
200 |
217 @task |
201 def relaunch_server(): |
218 def relaunch_server(do_collectstatic=True): |
202 print("Relaunch server") |
219 print("Relaunch server") |
203 collectstatic(env.remote_web_path, env.remote_virtualenv_path) |
220 if do_collectstatic: |
|
221 collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module) |
204 check_folder_access() |
222 check_folder_access() |
205 sudo(env.web_relaunch_cmd, shell=False) |
223 sudo(env.web_relaunch_cmd, shell=False) |
206 |
224 |
207 @task |
225 @task |
208 def sync_web(version): |
226 def sync_web(version): |