conf/fabfile.py
author ymh <ymh.work@gmail.com>
Fri, 28 Mar 2014 15:44:39 +0100
changeset 19 55fecd7b4ba7
parent 18 bc8e23448f4d
permissions -rw-r--r--
correct paramiko version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import imp
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import os.path
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
18
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     4
from fabric.api import task, env
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     5
from fabric.colors import green
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     6
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     7
import config  # @UnusedImport
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     8
from fablib import (export_version, do_sync_web, create_config,
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
     9
    clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    10
    clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp,
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    11
    do_relaunch_server)
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    12
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    13
12
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
@task
18
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    15
def relaunch_server(do_collectstatic=True, do_syncdb=True, do_check_folder_access=True):
12
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    print("Relaunch server")
18
bc8e23448f4d upgrade fablib
ymh <ymh.work@gmail.com>
parents: 12
diff changeset
    17
    do_relaunch_server(do_collectstatic, do_syncdb, env.get('check_folder_access',do_check_folder_access))
12
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
def sync_web(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    print(green("sync web with version %s" % version))
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    export_path_full = os.path.join(export_path,'web')
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    do_sync_web(version, export_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    create_config(export_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
def update_lib(version, package):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    print(green("update %s with version %s" % (package,version)))
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    export_path_full = os.path.join(export_path,'web')
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib")
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    f, pathname, description = imp.find_module("patch", [lib_path])
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    imp.load_module("patch", f, pathname, description)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    f, pathname, description = imp.find_module("lib_create_env", [lib_path])
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local'])
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    sync_install_build(package_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
def create_virtualenv(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    print(green("create virtualenv with version %s" % version))
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    export_path_web = os.path.join(export_path,'web')
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    venv_remote_export_path = ""
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    try:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        virtualenv_path = os.path.join(export_path_web, "virtualenv")
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv")
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    finally:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        if venv_remote_export_path:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
            clean_rsync_folder(venv_remote_export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
if len(env.repos) > 1:    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    @task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
    def sync_platform(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
        print(green("sync platform with version web %s" % (version)))
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
        export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
        
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        export_path_web = os.path.join(export_path,'web')
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
        do_sync_web(version, export_path_web)    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
        comp_versions = get_comp_versions_dict(export_path_web)  
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        for key in [k for k in env.repos if k != 'web']:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
            export_path_key = export_version(**{key: comp_versions[key]})
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
            export_path_comp = os.path.join(export_path_key, key)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
            do_sync_comp(key, export_path_comp)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
            clean_export_folder(export_path_key)    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
        create_config(export_path_web)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
        relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
for sync_name in [key for key in env.repos if key != 'web']:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    globals()[sync_name] = SyncComp(sync_name)