sbin/sync/fabfile.py
changeset 546 59d7cb99f4df
parent 545 1db91b735743
child 547 f19bef104a77
equal deleted inserted replaced
545:1db91b735743 546:59d7cb99f4df
     1 import imp
       
     2 import os.path
       
     3 import StringIO
       
     4 
       
     5 import config  # @UnusedImport
       
     6 from fablib import (export_version, do_sync_web, create_config,
       
     7                     clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv,
       
     8                     clean_rsync_folder, rsync_export, get_src_version, sync_build,
       
     9                     do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src)
       
    10 from fabric.api import task, env, run, cd, put
       
    11 from fabric.colors import green
       
    12 
       
    13 env.use_ssh_config = True
       
    14 
       
    15 def build_source(version):
       
    16     print(green("build source with version %s" % version))
       
    17     export_path = export_version(iconolab=version)
       
    18     export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root'])
       
    19     build_src(export_path_full)
       
    20     (_,version_str) = get_src_version(env.key, export_path_full)
       
    21     return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str))
       
    22 
       
    23 def do_create_virtualenv(remote_build_folder):
       
    24     requirements_path = os.path.join(remote_build_folder, env.repos[env.key]['requirements'])
       
    25     do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
       
    26     # add setting path to virtualenv
       
    27     ext_path = "import sys; sys.__plen = len(sys.path)\n"
       
    28     for l in env.remote_path.get('pythonpath', []):
       
    29         ext_path += l + "\n"
       
    30     ext_path += "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)"
       
    31     put(StringIO.StringIO(ext_path), os.path.join(env.remote_path['virtualenv'], 'lib/python%s/site-packages/_virtualenv_path_extensions.pth'%env.repos[env.key]['python_version']))
       
    32 
       
    33 @task
       
    34 def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False):
       
    35     print("Relaunch server")
       
    36     do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access))
       
    37 
       
    38 @task
       
    39 def sync_site(version):
       
    40     print(green("sync site and rebuild virtualenv with version %s" % version))
       
    41     build_path = build_source(version)
       
    42     run('mkdir -p "%s"' % env.remote_path['build_export'])
       
    43     res_trans = sync_build(build_path)
       
    44     # untar build
       
    45     with cd(env.remote_path['build_export']):
       
    46         run('tar zxf %s' % res_trans[0])
       
    47 
       
    48     do_create_virtualenv(res_trans[0][0:-7])
       
    49 
       
    50     # install build
       
    51     install_build(res_trans[0], env.remote_path['virtualenv'])
       
    52 
       
    53     # remove build + untared folder
       
    54     run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
       
    55     clean_export_folder(env.remote_path['build_export'])
       
    56     relaunch_server()
       
    57 
       
    58 @task
       
    59 def create_virtualenv(version):
       
    60     build_path = build_source(version)
       
    61     run('mkdir -p "%s"' % env.remote_path['build_export'])
       
    62     res_trans = sync_build(build_path)
       
    63     # untar build
       
    64     with cd(env.remote_path['build_export']):
       
    65         run('tar zxf %s' % res_trans[0])
       
    66 
       
    67     do_create_virtualenv(res_trans[0][0:-7])
       
    68 
       
    69     run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
       
    70     clean_export_folder(env.remote_path['build_export'])
       
    71 
       
    72 @task
       
    73 def sync_site_module(version):
       
    74     print(green("sync site with version %s" % version))
       
    75     build_path = build_source(version)
       
    76     run('mkdir -p "%s"' % env.remote_path['build_export'])
       
    77     res_trans = sync_build(build_path)
       
    78     # install build
       
    79     install_build(res_trans[0], env.remote_path['virtualenv'], env.platform_web_module)
       
    80 
       
    81     # remove build + untared folder
       
    82     run('rm -fr "%s"' % (res_trans[0]))
       
    83     clean_export_folder(env.remote_path['build_export'])
       
    84     relaunch_server()