sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Wed, 13 Jun 2012 01:11:17 +0200
changeset 71 a96f9d63755f
parent 69 8a0df65c065c
child 79 4afe089760bc
permissions -rw-r--r--
correct config creation
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
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
     4
from fabric.contrib.files import exists, upload_template
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
from mercurial import commands, ui, hg, cmdutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import imp
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import os, os.path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import shutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import sys
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
import config
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
def get_export_path(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    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
    15
    return os.path.expanduser(base_path) + "_%s" % (str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
def clean_export_folder(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    print("Removing %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    if os.path.isdir(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        shutil.rmtree(path, ignore_errors=True)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
def do_export_version(path, version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    print("Export version %s"%str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    #hgui = ui.ui() 
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    #repo = hg.repository(hgui, cmdutil.findrepo(os.getcwd()))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    #commands.archive(hgui, repo, path, rev=str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    local("hg archive -r \'%s\' \"%s\"" % (str(version),path))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    print("Export version %s done"%str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
def rsync_export(path, remotepath, filters):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    print("Rsync %s to %s",(path,remotepath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    if filters:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        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
    37
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        filter_option_str =""
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    run("mkdir -p \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    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
    42
    print("Rsync %s to %s done",(path,remotepath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
def clean_rsync_folder(remotepath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    print("clean rsync folder %s" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    run("rm -fr \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
def build_src(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    print("Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        f, pathname, description = imp.find_module("setup", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        print(" 2 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        setup_mod = imp.load_module("setup", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        print(" 3 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
            f.close()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    setup_mod.launch_setup("setup.py", ['sdist'])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
    print("Build source dist at %s done" % path)
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
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
def get_src_version(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    print("get src version at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        f, pathname, description = imp.find_module("ldt", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        ldt_mod = imp.load_module("ldt", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
            f.close()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    version = ldt_mod.VERSION
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    version_str = ldt_mod.get_version()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    return (version, version_str) 
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
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
def sync_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    print("Sync build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    with cd(env.remote_ldt_base_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        filename = os.path.basename(path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        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
    85
        print("Sync build %s to %s" % (path,repr(res_trans)))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        return res_trans
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
def remove_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
    print("remove build build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
    run("rm \"%s\"" % path)
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
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
def install_build(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    print("Install build %s in %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
    with prefix("source %s" % activate_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        run("pip install \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
def collectstatic(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
66
acc222517dc9 correct collect static
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   103
    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
   104
        run("python manage.py collectstatic --noinput")
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
        
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   106
def create_config(export_path):    
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   107
    print("Create config from %s" % (export_path,))
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   108
    remotepath = env.remote_web_path
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   109
    remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py")
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   110
    template_path = os.path.join(export_path, "web", env.platform_web_module, "config.py.tmpl")
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   111
    
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   112
    context = {
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   113
     'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/",
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   114
     'base_url': env.base_url,
71
a96f9d63755f correct config creation
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   115
     'web_url': env.web_url,
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   116
     'stream_url': env.stream_url,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   117
     'stream_src_prefix': env.stream_src_prefix,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   118
     'ffmpeg_path': env.ffmpeg_path,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   119
     'db_engine': env.db_engine,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   120
     'db_name': env.db_name,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   121
     'db_user': env.db_user,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   122
     'db_password': env.db_password,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   123
     'db_host': env.db_host,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   124
     'db_port': env.db_port,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   125
     'log_file': env.log_file,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   126
     'index_path': env.index_path,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   127
     'google_analytics_code': env.google_analytics_code,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   128
     'email_use_tls': env.email_use_tls,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   129
     'email_host': env.email_host,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   130
     'email_host_user': env.email_host_user,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   131
     'email_host_user': env.email_host_user,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   132
     'email_port': env.email_port,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   133
    }
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   134
    
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   135
    if not exists(remote_config_path, verbose=True):
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   136
        upload_template(template_path, remote_config_path, context=context)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
def export_version(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
    print("export version %s" % str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
    export_path = get_export_path(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
    do_export_version(export_path,version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    return export_path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
def do_create_virtualenv(remote_venv_export_path, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
    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
   150
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
    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
   152
        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
   153
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        prefix_str = "echo"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
    run("mkdir -p \"%s\"" % remotevirtualenvpath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
    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
   157
        run("python create_python_env.py")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
        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
   159
    with prefix("source \"%s\"" % activate_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
        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
   161
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
def do_sync_ldt(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
    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
   164
    src_path = export_path + "/src/ldt"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
    build_src(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    (_,version_str) = get_src_version(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
    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
   168
    res_trans = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
        res_trans = sync_build(build_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
        install_build(res_trans[0], env.remote_virtualenv_path)        
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
        if res_trans:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
            remove_build(res_trans[0])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
def do_sync_web(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
    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
   178
    web_path = os.path.join(export_path,"web/") 
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
    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
   180
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
def relaunch_server():
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
    print("Relaunch server")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    collectstatic(env.remote_web_path, env.remote_virtualenv_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
    sudo(env.web_relaunch_cmd, shell=False)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
def sync_web(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
    print(green("sync web with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
    export_path = export_version(version)
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   190
    do_sync_web(version, export_path)
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   191
    create_config(export_path)    
16
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
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
def sync_ldt(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    print(green("sync ldt with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
    relaunch_server()    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
def sync_platform(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
    print(green("sync platform with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
    do_sync_web(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
def create_virtualenv(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
    print(green("create virtualenv with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
    venv_remote_export_path = ""
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
        virtualenv_path = os.path.join(export_path, "virtualenv")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
    
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
        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
   221
        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
   222
        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
   223
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
        clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
        if venv_remote_export_path:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
            clean_rsync_folder(venv_remote_export_path)