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