sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Tue, 12 May 2015 14:57:27 +0200
changeset 244 4f07ad576fee
parent 193 a2c100af4e89
permissions -rw-r--r--
finalize django 1.8 migration, upgrade version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
     1
from distutils.util import strtobool
193
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     2
import imp
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     3
import os.path
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     4
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     5
from fablib import (export_version, do_sync_web, create_config,
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     6
    clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
     7
    clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp,
60
10e4b6eae0e5 sync script evolution for django-chunked-upload
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
     8
    do_relaunch_server)
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
     9
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    10
import config  # @UnusedImport
60
10e4b6eae0e5 sync script evolution for django-chunked-upload
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    11
from fabric.api import task, env
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
from fabric.colors import green
193
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    13
from fabric.tasks import execute
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    14
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    15
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    16
def _prep_bool_arg(arg): 
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    17
    return bool(strtobool(str(arg)))
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
@task
173
8b881fb925ef V.2.12.1 : update fabfile
cavaliet
parents: 109
diff changeset
    20
def relaunch_server(do_collectstatic=True, do_syncdb=True, do_check_folder_access=True):
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    print("Relaunch server")
173
8b881fb925ef V.2.12.1 : update fabfile
cavaliet
parents: 109
diff changeset
    22
    do_relaunch_server(do_collectstatic, do_syncdb, env.get('check_folder_access',do_check_folder_access))
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
@task
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    25
def sync_web(version, relaunch=True):
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    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
    27
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
    export_path_full = os.path.join(export_path,'web')
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
    do_sync_web(version, export_path_full)
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
    create_config(export_path_full)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    clean_export_folder(export_path)
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    32
    if _prep_bool_arg(relaunch):
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    33
        relaunch_server()
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
@task
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    36
def update_lib(version, package, relaunch=True):
109
2f2cc65284b0 small settings correction
ymh <ymh.work@gmail.com>
parents: 60
diff changeset
    37
    print(green("update %s with version %s" % (package,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
    38
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
    export_path_full = os.path.join(export_path,'web')
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
    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
    41
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    f, pathname, description = imp.find_module("patch", [lib_path])
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    43
    imp.load_module("patch", f, pathname, description)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    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
    45
    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
    46
    
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    47
    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
    48
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
    sync_install_build(package_path_full)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    clean_export_folder(export_path)
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    51
    if _prep_bool_arg(relaunch):
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    52
        relaunch_server()
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
@task
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    55
def sync_platform(version, relaunch=True):
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    56
    print(green("sync platform with version web %s" % (version)))
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    57
    export_path = export_version(web=version)
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
    export_path_web = os.path.join(export_path,'web')
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    60
    do_sync_web(version, export_path_web)    
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    61
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    62
    comp_versions = get_comp_versions_dict(export_path_web)  
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    63
47
7fc740f8553e correct fabfile
cavaliet
parents: 24
diff changeset
    64
    for key in [k for k in env.repos if k != 'web']:
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    65
        export_path_key = export_version(**{key: comp_versions[key]})
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    66
        export_path_comp = os.path.join(export_path_key, key)
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    67
        do_sync_comp(key, export_path_comp)
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    68
        clean_export_folder(export_path_key)    
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    69
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
    create_config(export_path_web)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    clean_export_folder(export_path)
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    72
    if _prep_bool_arg(relaunch):
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    73
        relaunch_server()
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
@task
193
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    76
def create_virtualenv(version, add_dep='no'):
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    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
    78
    export_path = export_version(web=version)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
    export_path_web = os.path.join(export_path,'web')
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
    venv_remote_export_path = ""
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
    try:
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
        virtualenv_path = os.path.join(export_path_web, "virtualenv")
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
        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
    85
        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
193
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    87
        
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    88
        if add_dep and add_dep.lower()[0] == 'y':
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    89
            for sync_name in [key for key in env.repos if key != 'web']:
a2c100af4e89 upgrade Pillow
ymh <ymh.work@gmail.com>
parents: 173
diff changeset
    90
                execute("sync_"+sync_name, version)
0
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
    finally:
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
        clean_export_folder(export_path)
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
        if venv_remote_export_path:
87104b7cb3d6 first version of file organization
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
            clean_rsync_folder(venv_remote_export_path)
1
5778de052a1b - update virtualenv
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
23
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    96
7df43b86c425 improve fabfile
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    97
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
    98
    globals()[sync_name] = SyncComp(sync_name)
244
4f07ad576fee finalize django 1.8 migration, upgrade version
ymh <ymh.work@gmail.com>
parents: 193
diff changeset
    99