|
1 from fabric.api import task, run, local, env, cd, put, prefix, sudo |
|
2 from fabric.colors import green |
|
3 from fabric.contrib.project import rsync_project |
|
4 from fabric.contrib.files import exists, upload_template |
|
5 from fabric.context_managers import settings |
|
6 from mercurial import commands, ui, hg, cmdutil |
|
7 import imp |
|
8 import os, os.path |
|
9 import shutil |
|
10 import sys |
|
11 |
|
12 import config |
|
13 |
|
14 def get_export_path(version): |
|
15 base_path = os.path.join(env.base_export_path,env.export_prefix).lstrip("/") |
|
16 return os.path.expanduser(base_path) + "_%s" % (str(version)) |
|
17 |
|
18 def clean_export_folder(path): |
|
19 print("Removing %s" % path) |
|
20 if os.path.isdir(path): |
|
21 shutil.rmtree(path, ignore_errors=True) |
|
22 |
|
23 def do_export_version(path, version): |
|
24 print("Export version %s"%str(version)) |
|
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)) |
|
31 print("Export version %s done"%str(version)) |
|
32 |
|
33 def rsync_export(path, remotepath, filters): |
|
34 print("Rsync %s to %s",(path,remotepath)) |
|
35 |
|
36 if filters: |
|
37 filter_option_str = " ".join(["--filter \"%s\"" % (f) for f in filters]) |
|
38 else: |
|
39 filter_option_str ="" |
|
40 |
|
41 run("mkdir -p \"%s\"" % remotepath) |
|
42 rsync_project(remotepath, local_dir=path, extra_opts=filter_option_str, delete=True) |
|
43 print("Rsync %s to %s done",(path,remotepath)) |
|
44 |
|
45 def clean_rsync_folder(remotepath): |
|
46 print("clean rsync folder %s" % remotepath) |
|
47 run("rm -fr \"%s\"" % remotepath) |
|
48 |
|
49 |
|
50 def export_version(version): |
|
51 print("export version %s" % str(version)) |
|
52 |
|
53 export_path = get_export_path(version) |
|
54 |
|
55 clean_export_folder(export_path) |
|
56 do_export_version(export_path,version) |
|
57 |
|
58 return export_path |
|
59 |
|
60 def do_sync_web(version, export_path): |
|
61 print("do_sync_web with version %s and path %s" % (version,export_path)) |
|
62 web_path = os.path.join(export_path,"front_idill/") |
|
63 rsync_export(web_path, env.remote_web_path, env.web_rsync_filters) |
|
64 |
|
65 def relaunch_server(): |
|
66 print("Relaunch server") |
|
67 sudo(env.web_relaunch_cmd, shell=False) |
|
68 |
|
69 @task |
|
70 def sync_web(version): |
|
71 print(green("sync web with version %s" % version)) |
|
72 export_path = export_version(version) |
|
73 do_sync_web(version, export_path) |
|
74 create_config(export_path) |
|
75 clean_export_folder(export_path) |
|
76 relaunch_server() |