sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Mon, 29 Jul 2024 23:18:55 +0200
changeset 131 2a18dfe8bfc0
parent 96 900b29a370ae
permissions -rw-r--r--
last change before install
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
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
     5
from fabric.context_managers import settings
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from mercurial import commands, ui, hg, cmdutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import imp
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import os, os.path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import shutil
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
import sys
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
import config
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
def get_export_path(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    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
    16
    return os.path.expanduser(base_path) + "_%s" % (str(version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
def clean_export_folder(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    print("Removing %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    if os.path.isdir(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        shutil.rmtree(path, ignore_errors=True)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
def do_export_version(path, version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    print("Export version %s"%str(version))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    25
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    26
    #hgui = ui.ui()
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    #repo = hg.repository(hgui, cmdutil.findrepo(os.getcwd()))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    #commands.archive(hgui, repo, path, rev=str(version))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    29
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    local("hg archive -r \'%s\' \"%s\"" % (str(version),path))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    print("Export version %s done"%str(version))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    32
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
def rsync_export(path, remotepath, filters):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    print("Rsync %s to %s",(path,remotepath))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    35
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    if filters:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        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
    38
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        filter_option_str =""
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    40
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    run("mkdir -p \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    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
    43
    print("Rsync %s to %s done",(path,remotepath))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    44
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
def clean_rsync_folder(remotepath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    print("clean rsync folder %s" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    run("rm -fr \"%s\"" % remotepath)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    48
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
def build_src(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    print("Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
        f, pathname, description = imp.find_module("setup", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        print(" 2 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        setup_mod = imp.load_module("setup", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        print(" 3 Build source dist at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
            f.close()
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    60
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    setup_mod.launch_setup("setup.py", ['sdist'])
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    62
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    print("Build source dist at %s done" % path)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    64
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
def get_src_version(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    print("get src version at %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
    f = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        f, pathname, description = imp.find_module("ldt", [path])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        ldt_mod = imp.load_module("ldt", f, pathname, description)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        if f:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
            f.close()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    version = ldt_mod.VERSION
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    version_str = ldt_mod.get_version()
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    77
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    78
    return (version, version_str)
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    79
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
def sync_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
    print("Sync build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    with cd(env.remote_ldt_base_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        filename = os.path.basename(path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        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
    86
        print("Sync build %s to %s" % (path,repr(res_trans)))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        return res_trans
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
def remove_build(path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
    print("remove build build %s" % path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
    run("rm \"%s\"" % path)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    92
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
def install_build(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    print("Install build %s in %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
    97
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    with prefix("source %s" % activate_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
        run("pip install \"%s\"" % remotepath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
def collectstatic(remotepath, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
    print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
66
acc222517dc9 correct collect static
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   104
    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
86
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   105
        run("python manage.py collectstatic -c --noinput")
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   106
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   107
def create_config(export_path):
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   108
    print("Create config from %s" % (export_path,))
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   109
    remotepath = env.remote_web_path
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   110
    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
   111
    template_path = os.path.join(export_path, "web", env.platform_web_module, "config.py.tmpl")
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   112
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   113
    context = {
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   114
     'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/",
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   115
     'base_url': env.base_url,
71
a96f9d63755f correct config creation
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   116
     'web_url': env.web_url,
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   117
     'stream_url': env.stream_url,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   118
     'stream_src_prefix': env.stream_src_prefix,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   119
     'ffmpeg_path': env.ffmpeg_path,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   120
     'db_engine': env.db_engine,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   121
     'db_name': env.db_name,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   122
     'db_user': env.db_user,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   123
     'db_password': env.db_password,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   124
     'db_host': env.db_host,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   125
     'db_port': env.db_port,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   126
     'log_file': env.log_file,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   127
     'index_path': env.index_path,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   128
     'google_analytics_code': env.google_analytics_code,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   129
     'email_use_tls': env.email_use_tls,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   130
     'email_host': env.email_host,
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_host_user': env.email_host_user,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   133
     'email_port': env.email_port,
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   134
    }
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   135
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   136
    if not exists(remote_config_path, verbose=True):
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   137
        upload_template(template_path, remote_config_path, context=context)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
def export_version(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
    print("export version %s" % str(version))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   141
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
    export_path = get_export_path(version)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   143
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
    do_export_version(export_path,version)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   146
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    return export_path
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
def do_create_virtualenv(remote_venv_export_path, remotevirtualenvpath):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
    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
   151
    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    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
   153
        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
   154
    else:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
        prefix_str = "echo"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
    run("mkdir -p \"%s\"" % remotevirtualenvpath)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
    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
   158
        run("python create_python_env.py")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
        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
   160
    with prefix("source \"%s\"" % activate_path):
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   161
        run("pip install -i https://pypi.python.org/simple -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt"))
16
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
def do_sync_ldt(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
    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
   165
    src_path = export_path + "/src/ldt"
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
    build_src(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
    (_,version_str) = get_src_version(src_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
    build_path = os.path.join(src_path,"dist","ldt-%s.tar.gz" % version_str)
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   169
    sync_install_build(build_path)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   170
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   171
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   172
def sync_install_build(build_path):
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    res_trans = None
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
        res_trans = sync_build(build_path)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   176
        install_build(res_trans[0], env.remote_virtualenv_path)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
        if res_trans:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
            remove_build(res_trans[0])
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   181
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
def do_sync_web(version, export_path):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
    print("do_sync_web with version %s and path %s" % (version,export_path))
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   184
    web_path = os.path.join(export_path,"web/")
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   185
    rsync_export(web_path, env.remote_web_path, env.web_rsync_filters)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
def relaunch_server():
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
    print("Relaunch server")
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
    collectstatic(env.remote_web_path, env.remote_virtualenv_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    sudo(env.web_relaunch_cmd, shell=False)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   191
86
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   192
def check_folder_access():
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   193
    print("Check folder access")
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   194
    # get remote user
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   195
    for folder_path in env.folders:
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   196
        if not os.path.isabs(folder_path):
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   197
            folder_path = env.remote_web_path.rstrip("/")+ "/" + folder_path
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   198
            with settings(warn_only=True):
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   199
                if not exists(folder_path):
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   200
                    run("mkdir -p \"%s\"" % folder_path)
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   201
                run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path))
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   202
                run("chown -R -c g+w \"%s\"" % folder_path)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
def sync_web(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
    print(green("sync web with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
    export_path = export_version(version)
69
8a0df65c065c add create config
ymh <ymh.work@gmail.com>
parents: 68
diff changeset
   208
    do_sync_web(version, export_path)
86
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   209
    check_folder_access()
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   210
    create_config(export_path)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
def sync_ldt(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
    print(green("sync ldt with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
    clean_export_folder(export_path)
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   220
    relaunch_server()
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   221
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   222
@task
82
cb842369c5ca generalize package update
ymh <ymh.work@gmail.com>
parents: 79
diff changeset
   223
def update_lib(version, package):
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   224
    print(green("update ldt with version %s" % version))
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   225
    export_path = export_version(version)
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   226
    lib_path = os.path.join(export_path, "virtualenv", "res", "lib")
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   227
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   228
    f, pathname, description = imp.find_module("patch", [lib_path])
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   229
    patch = imp.load_module("patch", f, pathname, description)
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   230
    f, pathname, description = imp.find_module("lib_create_env", [lib_path])
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   231
    lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   232
82
cb842369c5ca generalize package update
ymh <ymh.work@gmail.com>
parents: 79
diff changeset
   233
    package_path = os.path.join(export_path, "virtualenv", "res", "src", lib_create_env.URLS[package]['local'])
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   234
82
cb842369c5ca generalize package update
ymh <ymh.work@gmail.com>
parents: 79
diff changeset
   235
    sync_install_build(package_path)
79
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   236
    clean_export_folder(export_path)
4afe089760bc add a method to update ldt platform without release
ymh <ymh.work@gmail.com>
parents: 71
diff changeset
   237
    relaunch_server()
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   238
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
def sync_platform(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
    print(green("sync platform with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
    do_sync_ldt(version, export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
    do_sync_web(version, export_path)
86
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   245
    check_folder_access()
bb39eafd5293 correction on sync fab files
ymh <ymh.work@gmail.com>
parents: 82
diff changeset
   246
    create_config(export_path)
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
    clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
    relaunch_server()
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
@task
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
def create_virtualenv(version):
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
    print(green("create virtualenv with version %s" % version))
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
    export_path = export_version(version)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
    venv_remote_export_path = ""
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
    try:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
        virtualenv_path = os.path.join(export_path, "virtualenv")
96
900b29a370ae Force the use of https for the pypi index when installing the server dependencies.
ymh <ymh.work@gmail.com>
parents: 86
diff changeset
   257
16
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
        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
   259
        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
   260
        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
   261
    finally:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
        clean_export_folder(export_path)
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
        if venv_remote_export_path:
e37a29d23c86 First version of tralalere platform
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
            clean_rsync_folder(venv_remote_export_path)