sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Fri, 27 Jan 2017 12:15:02 +0100
changeset 305 75e6a9eddd7c
parent 174 b91ae400f66d
permissions -rw-r--r--
Added tag 0.0.20 for changeset d8dea8f7e3cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import imp
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import os.path
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import StringIO
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import config  # @UnusedImport
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from fablib import (export_version, do_sync_web, create_config,
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
                    clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
                    clean_rsync_folder, rsync_export, get_src_version, sync_build,
162
f014c1593ade smal modification to get version
ymh <ymh.work@gmail.com>
parents: 159
diff changeset
     9
                    do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src)
166
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    10
from fabric.api import task, env, run, cd, put
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
from fabric.colors import green
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
166
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    13
env.use_ssh_config = True
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    14
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
def build_source(version):
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    print(green("build source with version %s" % version))
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    export_path = export_version(iconolab=version)
162
f014c1593ade smal modification to get version
ymh <ymh.work@gmail.com>
parents: 159
diff changeset
    18
    export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root'])
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    build_src(export_path_full)
162
f014c1593ade smal modification to get version
ymh <ymh.work@gmail.com>
parents: 159
diff changeset
    20
    (_,version_str) = get_src_version(env.key, export_path_full)
166
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    21
    return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str))
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    23
def do_create_virtualenv(remote_build_folder):
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    24
    requirements_path = os.path.join(remote_build_folder, env.repos[env.key]['requirements'])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    25
    do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    26
    # add setting path to virtualenv
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    27
    ext_path = "import sys; sys.__plen = len(sys.path)\n"
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    28
    for l in env.remote_path.get('pythonpath', []):
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    29
        ext_path += l + "\n"
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    30
    ext_path += "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)"
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    31
    put(StringIO.StringIO(ext_path), os.path.join(env.remote_path['virtualenv'], 'lib/python%s/site-packages/_virtualenv_path_extensions.pth'%env.repos[env.key]['python_version']))
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    32
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
@task
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False):
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    print("Relaunch server")
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access))
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
@task
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
def sync_site(version):
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    40
    print(green("sync site and rebuild virtualenv with version %s" % version))
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    build_path = build_source(version)
166
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    42
    run('mkdir -p "%s"' % env.remote_path['build_export'])
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    res_trans = sync_build(build_path)
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    # untar build
166
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    45
    with cd(env.remote_path['build_export']):
e9cd38b7cfe0 improve install script + correct base settings
ymh <ymh.work@gmail.com>
parents: 162
diff changeset
    46
        run('tar zxf %s' % res_trans[0])
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    47
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    48
    do_create_virtualenv(res_trans[0][0:-7])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    49
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    # install build
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    install_build(res_trans[0], env.remote_path['virtualenv'])
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    52
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    # remove build + untared folder
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
171
9b019ac3b791 correct fabfile
ymh <ymh.work@gmail.com>
parents: 166
diff changeset
    55
    clean_export_folder(env.remote_path['build_export'])
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    relaunch_server()
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
@task
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
def create_virtualenv(version):
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    60
    build_path = build_source(version)
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    61
    run('mkdir -p "%s"' % env.remote_path['build_export'])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    62
    res_trans = sync_build(build_path)
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    63
    # untar build
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    64
    with cd(env.remote_path['build_export']):
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    65
        run('tar zxf %s' % res_trans[0])
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    67
    do_create_virtualenv(res_trans[0][0:-7])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    68
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    69
    run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    70
    clean_export_folder(env.remote_path['build_export'])
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    72
@task
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    73
def sync_site_module(version):
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    74
    print(green("sync site with version %s" % version))
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    75
    build_path = build_source(version)
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    76
    run('mkdir -p "%s"' % env.remote_path['build_export'])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    77
    res_trans = sync_build(build_path)
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    78
    # install build
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    79
    install_build(res_trans[0], env.remote_path['virtualenv'], env.platform_web_module)
159
a2e6d314da2f add sync scripts
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
174
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    81
    # remove build + untared folder
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    82
    run('rm -fr "%s"' % (res_trans[0]))
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    83
    clean_export_folder(env.remote_path['build_export'])
b91ae400f66d clean task, add task to sync only the module and create the virtualenv (without the module)
ymh <ymh.work@gmail.com>
parents: 171
diff changeset
    84
    relaunch_server()