conf/fabfile.py
author ymh <ymh.work@gmail.com>
Wed, 19 Jun 2013 18:50:09 +0200
changeset 12 18274a40d683
child 18 bc8e23448f4d
permissions -rw-r--r--
update config template and add fabfile.py reference
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
from fablib import (export_version, do_sync_web, create_config, 
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
    clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv, 
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
    clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp, 
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    do_relaunch_server)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
from fabric.api import task, env
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from fabric.colors import green
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import config #@UnusedImport
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import imp
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import os.path
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
def relaunch_server(do_collectstatic=True, do_syncdb=True):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    print("Relaunch server")
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    do_relaunch_server(do_collectstatic, do_syncdb)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
def sync_web(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    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
    19
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    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
    21
    do_sync_web(version, export_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    create_config(export_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
def update_lib(version, package):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    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
    29
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    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
    31
    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
    32
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    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
    34
    imp.load_module("patch", f, pathname, description)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    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
    36
    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
    37
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    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
    39
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    sync_install_build(package_path_full)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
@task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
def create_virtualenv(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    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
    48
    export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    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
    50
    venv_remote_export_path = ""
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    try:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        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
    53
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
        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
    55
        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
    56
        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
    57
    finally:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        if venv_remote_export_path:
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            clean_rsync_folder(venv_remote_export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
if len(env.repos) > 1:    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    @task
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    def sync_platform(version):
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        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
    66
        export_path = export_version(web=version)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
        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
    69
        do_sync_web(version, export_path_web)    
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
        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
    72
    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
        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
    74
            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
    75
            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
    76
            do_sync_comp(key, export_path_comp)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
            clean_export_folder(export_path_key)    
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        create_config(export_path_web)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        clean_export_folder(export_path)
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        relaunch_server()
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
18274a40d683 update config template and add fabfile.py reference
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
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
    84
    globals()[sync_name] = SyncComp(sync_name)