sbin/sync/fabfile.py
author ymh <ymh.work@gmail.com>
Fri, 19 Jul 2024 09:38:03 +0200
changeset 704 b5835dca2624
parent 557 f82f7bc4e13f
permissions -rw-r--r--
Adapt renkan preview to uses chrome headless/puppeteer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
350
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import imp
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import os.path
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from fablib import (export_version, do_sync_web, create_config,
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
    clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
    clean_rsync_folder, rsync_export, get_comp_versions_dict, SyncComp,
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    do_relaunch_server)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
from fabric.api import task, env
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
from fabric.colors import green
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
from fabric.tasks import execute
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
import config  # @UnusedImport
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
@task
557
f82f7bc4e13f udate sync scripts
ymh <ymh.work@gmail.com>
parents: 350
diff changeset
    16
def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=True):
350
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    print("Relaunch server")
557
f82f7bc4e13f udate sync scripts
ymh <ymh.work@gmail.com>
parents: 350
diff changeset
    18
    do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access))
350
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
@task
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
def sync_web(version):
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    print(green("sync web with version %s" % version))
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    export_path = export_version(web=version)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    export_path_full = os.path.join(export_path,'web')
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    do_sync_web(version, export_path_full)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
    create_config(export_path_full)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    clean_export_folder(export_path)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    relaunch_server()
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
@task
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
def update_lib(version, package):
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    print(green("update %s with version %s" % (package,version)))
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    export_path = export_version(web=version)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    export_path_full = os.path.join(export_path,'web')
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    lib_path = os.path.join(export_path_full, "virtualenv", "res", "lib")
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    f, pathname, description = imp.find_module("patch", [lib_path])
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    imp.load_module("patch", f, pathname, description)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    f, pathname, description = imp.find_module("lib_create_env", [lib_path])
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    lib_create_env = imp.load_module("lib_create_env", f, pathname, description)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    package_path_full = os.path.join(export_path_full, "virtualenv", "res", "src", lib_create_env.URLS[package]['local'])
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    sync_install_build(package_path_full)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    clean_export_folder(export_path)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    relaunch_server()
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
@task
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
def sync_platform(version):
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    print(green("sync hdalab with version web %s" % (version)))
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    export_path = export_version(web=version)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    export_path_web = os.path.join(export_path,'web')
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    do_sync_web(version, export_path_web)    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    comp_versions = get_comp_versions_dict(export_path_web)  
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    for key in [k for k in env.repos if k != 'web']:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        export_path_key = export_version(**{key: comp_versions[key]})
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        export_path_comp = os.path.join(export_path_key, key)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
        do_sync_comp(key, export_path_comp)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        clean_export_folder(export_path_key)    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    create_config(export_path_web)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
    clean_export_folder(export_path)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
    relaunch_server()
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
@task
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
def create_virtualenv(version, add_dep='no'):
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    print(green("create virtualenv with version %s" % version))
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    export_path = export_version(web=version)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    export_path_web = os.path.join(export_path,'web')
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    venv_remote_export_path = ""
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    try:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        virtualenv_path = os.path.join(export_path_web, "virtualenv")
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv")
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
        
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
        if add_dep and add_dep.lower()[0] == 'y':
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
            for sync_name in [key for key in env.repos if key != 'web']:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
                execute("sync_"+sync_name, version)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    finally:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
        clean_export_folder(export_path)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
        if venv_remote_export_path:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
            clean_rsync_folder(venv_remote_export_path)
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
for sync_name in [key for key in env.repos if key != 'web']:
4f2fe8731353 add fabfile for server synchronisation
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
    globals()[sync_name] = SyncComp(sync_name)