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