sbin/sync/fabfile.py
author cavaliet
Wed, 09 Apr 2014 15:17:33 +0200
changeset 368 15063d46eec6
parent 367 7b8c98663823
permissions -rw-r--r--
Added tag V00.72 for changeset 7b8c98663823
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
from fabric.api import task, env, sudo
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from fablib import (export_version, do_sync_web, create_config, 
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
    clean_export_folder, sync_install_build, do_create_virtualenv, 
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    clean_rsync_folder, rsync_export, do_relaunch_server)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from fabric.colors import green
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import imp
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import os.path
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import config
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
@task
367
7b8c98663823 v0.72 css correct
cavaliet
parents: 1
diff changeset
    12
def relaunch_server(do_collectstatic=True, do_syncdb=True, do_check_folder_access=True):
1
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    print("Relaunch server")
367
7b8c98663823 v0.72 css correct
cavaliet
parents: 1
diff changeset
    14
    do_relaunch_server(do_collectstatic, do_syncdb, env.get('check_folder_access',do_check_folder_access))
1
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
@task
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
def sync_web(version):
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    print(green("sync web with version %s" % version))
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    export_path = export_version(web=version)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    export_path_full = os.path.join(export_path,'web')
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    do_sync_web(version, export_path_full)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    create_config(export_path_full)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    clean_export_folder(export_path)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    relaunch_server()
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
@task
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
def update_lib(version, package):
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    print(green("update %s with version %s" % (package,version)))
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    export_path = export_version(web=version)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    export_path_full = os.path.join(export_path,'web')
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib")
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    f, pathname, description = imp.find_module("patch", [lib_path])
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    imp.load_module("patch", f, pathname, description)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    f, pathname, description = imp.find_module("lib_create_env", [lib_path])
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    
4a14963334f4 add sync files
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'])
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    sync_install_build(package_path_full)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    clean_export_folder(export_path)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    relaunch_server()
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
@task
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
def create_virtualenv(version):
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    print(green("create virtualenv with version %s" % version))
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    export_path = export_version(web=version)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    export_path_web = os.path.join(export_path,'web')
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    venv_remote_export_path = ""
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    try:
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        virtualenv_path = os.path.join(export_path_web, "virtualenv")
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    
4a14963334f4 add sync files
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")
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    finally:
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        clean_export_folder(export_path)
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        if venv_remote_export_path:
4a14963334f4 add sync files
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            clean_rsync_folder(venv_remote_export_path)