sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Tue, 04 Dec 2012 10:19:44 +0100
changeset 24 6b79d5424407
parent 23 7df43b86c425
child 47 7fc740f8553e
permissions -rw-r--r--
correct fabfile and test requirement.txt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
     1
from fabric.api import task, env, sudo
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from fabric.colors import green
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
     3
from ldt_fablib import (check_folder_access, syncdb, collectstatic, 
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
     4
    export_version, do_sync_web, create_config, clean_export_folder, do_sync_comp, 
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
     5
    sync_install_build, do_create_virtualenv, clean_rsync_folder, rsync_export, 
24
6b79d5424407 correct fabfile and test requirement.txt
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
     6
    get_comp_versions_dict, SyncComp, do_relaunch_server)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import imp
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
     8
import os.path
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
@task
11
fc7cc9667de1 add syncdb to relaunch server
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    11
def relaunch_server(do_collectstatic=True, do_syncdb=True):
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    print("Relaunch server")
24
6b79d5424407 correct fabfile and test requirement.txt
ymh <ymh.work@gmail.com>
parents: 23
diff changeset
    13
    do_relaunch_server(do_collectstatic, do_syncdb)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
@task
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
def sync_web(version):
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    print(green("sync web with version %s" % version))
3
800c48d0e3c1 Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents: 1
diff changeset
    18
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
    export_path_full = os.path.join(export_path,'web')
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
    do_sync_web(version, export_path_full)
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
    create_config(export_path_full)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    clean_export_folder(export_path)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    relaunch_server()
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
@task
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
def update_lib(version, package):
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    print(green("update ldt with version %s" % version))
3
800c48d0e3c1 Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents: 1
diff changeset
    28
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
    export_path_full = os.path.join(export_path,'web')
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
    lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib")
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    f, pathname, description = imp.find_module("patch", [lib_path])
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    33
    imp.load_module("patch", f, pathname, description)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    f, pathname, description = imp.find_module("lib_create_env", [lib_path])
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    37
    package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local'])
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
    sync_install_build(package_path_full)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    clean_export_folder(export_path)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    relaunch_server()
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
@task
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    44
def sync_platform(version):
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    45
    print(green("sync platform with version web %s" % (version)))
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    46
    export_path = export_version(web=version)
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    47
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
    export_path_web = os.path.join(export_path,'web')
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    49
    do_sync_web(version, export_path_web)    
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    50
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    51
    comp_versions = get_comp_versions_dict(export_path_web)  
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    52
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    53
    for key in [k for k in env.repos if key != 'web']:
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    54
        export_path_key = export_version(**{key: comp_versions[key]})
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    55
        export_path_comp = os.path.join(export_path_key, key)
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    56
        do_sync_comp(key, export_path_comp)
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    57
        clean_export_folder(export_path_key)    
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    58
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
    create_config(export_path_web)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    clean_export_folder(export_path)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    relaunch_server()
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
@task
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
def create_virtualenv(version):
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
    print(green("create virtualenv with version %s" % version))
3
800c48d0e3c1 Correct fab file for being able to pass 2 versions : ldt and web
ymh <ymh.work@gmail.com>
parents: 1
diff changeset
    66
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
    export_path_web = os.path.join(export_path,'web')
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
    venv_remote_export_path = ""
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
    try:
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
        virtualenv_path = os.path.join(export_path_web, "virtualenv")
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
        venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv")
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    finally:
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        clean_export_folder(export_path)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        if venv_remote_export_path:
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
            clean_rsync_folder(venv_remote_export_path)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    80
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    81
for sync_name in [key for key in env.repos if key != 'web']:
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    82
    globals()[sync_name] = SyncComp(sync_name)