sbin/sync/fabfile.py
changeset 166 e9cd38b7cfe0
parent 162 f014c1593ade
child 171 9b019ac3b791
equal deleted inserted replaced
165:11600deeaaee 166:e9cd38b7cfe0
     5 import config  # @UnusedImport
     5 import config  # @UnusedImport
     6 from fablib import (export_version, do_sync_web, create_config,
     6 from fablib import (export_version, do_sync_web, create_config,
     7                     clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
     7                     clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
     8                     clean_rsync_folder, rsync_export, get_src_version, sync_build,
     8                     clean_rsync_folder, rsync_export, get_src_version, sync_build,
     9                     do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src)
     9                     do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src)
    10 from fabric.api import task, env
    10 from fabric.api import task, env, run, cd, put
    11 from fabric.colors import green
    11 from fabric.colors import green
       
    12 
       
    13 env.use_ssh_config = True
    12 
    14 
    13 def build_source(version):
    15 def build_source(version):
    14     print(green("build source with version %s" % version))
    16     print(green("build source with version %s" % version))
    15     export_path = export_version(iconolab=version)
    17     export_path = export_version(iconolab=version)
    16     export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root'])
    18     export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root'])
    17     build_src(export_path_full)
    19     build_src(export_path_full)
    18     (_,version_str) = get_src_version(env.key, export_path_full)
    20     (_,version_str) = get_src_version(env.key, export_path_full)
    19     return os.path.join(src_path,"dist","%s-%s.tar.gz" % (env.key,version_str))
    21     return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str))
    20 
    22 
    21 @task
    23 @task
    22 def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False):
    24 def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False):
    23     print("Relaunch server")
    25     print("Relaunch server")
    24     do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access))
    26     do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access))
    25 
    27 
    26 @task
    28 @task
    27 def sync_site(version):
    29 def sync_site(version):
    28     print(green("sync site with version %s" % version))
    30     print(green("sync site with version %s" % version))
    29     build_path = build_source(version)
    31     build_path = build_source(version)
       
    32     run('mkdir -p "%s"' % env.remote_path['build_export'])
    30     res_trans = sync_build(build_path)
    33     res_trans = sync_build(build_path)
    31     # untar build
    34     # untar build
    32     run('tar zxf %s' % res_trans[0])
    35     with cd(env.remote_path['build_export']):
       
    36         run('tar zxf %s' % res_trans[0])
    33     # rebuild virtualenv
    37     # rebuild virtualenv
    34     requirements_path = os.path.join(res_trans[0][0:-7], env.repos[env.key]['requirements'])
    38     requirements_path = os.path.join(res_trans[0][0:-7], env.repos[env.key]['requirements'])
    35     do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
    39     do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
    36     # add setting path to virtualenv
    40     # add setting path to virtualenv
    37     ext_path = "import sys; sys.__plen = len(sys.path)\n"
    41     ext_path = "import sys; sys.__plen = len(sys.path)\n"