sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Tue, 12 Jun 2012 18:37:23 +0200
changeset 68 80c372a0485e
parent 67 2a27231c10d4
child 69 8a0df65c065c
permissions -rw-r--r--
correct collect static
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
from fabric.api import task, run, local, env, cd, put, prefix, sudo
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from fabric.colors import green
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from fabric.contrib.project import rsync_project
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from mercurial import commands, ui, hg, cmdutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import imp
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import os, os.path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import shutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import sys
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
import config
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
def get_export_path(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    base_path = os.path.join(env.base_export_path,env.export_prefix).lstrip("/")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    return os.path.expanduser(base_path) + "_%s" % (str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
def clean_export_folder(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    print("Removing %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    if os.path.isdir(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        shutil.rmtree(path, ignore_errors=True)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
def do_export_version(path, version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    print("Export version %s"%str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    #hgui = ui.ui() 
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    #repo = hg.repository(hgui, cmdutil.findrepo(os.getcwd()))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    #commands.archive(hgui, repo, path, rev=str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    local("hg archive -r \'%s\' \"%s\"" % (str(version),path))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    print("Export version %s done"%str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
def rsync_export(path, remotepath, filters):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    print("Rsync %s to %s",(path,remotepath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    if filters:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        filter_option_str = " ".join(["--filter \"%s\"" % (f) for f in filters])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        filter_option_str =""
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    run("mkdir -p \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    rsync_project(remotepath, local_dir=path, extra_opts=filter_option_str, delete=True)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    print("Rsync %s to %s done",(path,remotepath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
def clean_rsync_folder(remotepath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    print("clean rsync folder %s" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    run("rm -fr \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
def build_src(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    print("Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
        f, pathname, description = imp.find_module("setup", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        print(" 2 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        setup_mod = imp.load_module("setup", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        print(" 3 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
            f.close()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
    setup_mod.launch_setup("setup.py", ['sdist'])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    print("Build source dist at %s done" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
def get_src_version(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
    print("get src version at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
        f, pathname, description = imp.find_module("ldt", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        ldt_mod = imp.load_module("ldt", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
            f.close()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    version = ldt_mod.VERSION
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    version_str = ldt_mod.get_version()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    return (version, version_str) 
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
def sync_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    print("Sync build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    with cd(env.remote_ldt_base_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
        filename = os.path.basename(path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        res_trans = put(path, os.path.join(env.remote_ldt_base_path, filename))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        print("Sync build %s to %s" % (path,repr(res_trans)))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        return res_trans
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
def remove_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    print("remove build build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
    run("rm \"%s\"" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
def install_build(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
    print("Install build %s in %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    with prefix("source %s" % activate_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        run("pip install \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
def collectstatic(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
    print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
66
acc222517dc9 correct collect static
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   102
    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
68
80c372a0485e correct collect static
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   103
        run("python manage.py collectstatic --noinput")
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
def export_version(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
    print("export version %s" % str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
    export_path = get_export_path(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
    do_export_version(export_path,version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
    return export_path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
def do_create_virtualenv(remote_venv_export_path, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
    print("Create virtualenv export_path : %s - remote venvpath : %s" % (remote_venv_export_path, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
    if "remote_baseline_venv" in env and env.remote_baseline_venv:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
        prefix_str = "source \"%s\"" % os.path.join(env.remote_baseline_venv, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
        prefix_str = "echo"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
    run("mkdir -p \"%s\"" % remotevirtualenvpath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
    with prefix(prefix_str), cd(os.path.join(remote_venv_export_path,"virtualenv","web")):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
        run("python create_python_env.py")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
        run("python project-boot.py --unzip-setuptools --no-site-packages --clear --type-install=local \"%s\"" % remotevirtualenvpath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
    with prefix("source \"%s\"" % activate_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
        run("pip install -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt"))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
def do_sync_ldt(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
    print("do_sync_ldt with version %s and path %s" % (version,export_path))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
    src_path = export_path + "/src/ldt"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
    build_src(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
    (_,version_str) = get_src_version(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
    build_path = os.path.join(src_path,"dist","ldt-%s.tar.gz" % version_str)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
    res_trans = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
        res_trans = sync_build(build_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
        install_build(res_trans[0], env.remote_virtualenv_path)        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
        if res_trans:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
            remove_build(res_trans[0])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
def do_sync_web(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    print("do_sync_web with version %s and path %s" % (version,export_path))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    web_path = os.path.join(export_path,"web/") 
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
    rsync_export(web_path, env.remote_web_path, env.web_rsync_filters)    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
def relaunch_server():
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
    print("Relaunch server")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    collectstatic(env.remote_web_path, env.remote_virtualenv_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
    sudo(env.web_relaunch_cmd, shell=False)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
def sync_web(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
    print(green("sync web with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
    do_sync_web(version, export_path)    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
def sync_ldt(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
    print(green("sync ldt with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
    relaunch_server()    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
def sync_platform(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    print(green("sync platform with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
    do_sync_web(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
def create_virtualenv(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
    print(green("create virtualenv with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
    venv_remote_export_path = ""
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
        virtualenv_path = os.path.join(export_path, "virtualenv")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
        venv_remote_export_path = os.path.join(env.remote_venv_export_path, env.export_prefix, version,"virtualenv")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
        rsync_export(virtualenv_path, venv_remote_export_path, env.venv_rsync_filters)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
        do_create_virtualenv(venv_remote_export_path, env.remote_virtualenv_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
        clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
        if venv_remote_export_path:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
            clean_rsync_folder(venv_remote_export_path)