clean task, add task to sync only the module and create the virtualenv (without the module)
authorymh <ymh.work@gmail.com>
Fri, 02 Sep 2016 13:37:02 +0200
changeset 174 b91ae400f66d
parent 173 7de04dac97e6
child 175 2e9d67d25d48
clean task, add task to sync only the module and create the virtualenv (without the module)
sbin/sync/fabfile.py
--- a/sbin/sync/fabfile.py	Fri Sep 02 02:03:01 2016 +0200
+++ b/sbin/sync/fabfile.py	Fri Sep 02 13:37:02 2016 +0200
@@ -20,6 +20,16 @@
     (_,version_str) = get_src_version(env.key, export_path_full)
     return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str))
 
+def do_create_virtualenv(remote_build_folder):
+    requirements_path = os.path.join(remote_build_folder, env.repos[env.key]['requirements'])
+    do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
+    # add setting path to virtualenv
+    ext_path = "import sys; sys.__plen = len(sys.path)\n"
+    for l in env.remote_path.get('pythonpath', []):
+        ext_path += l + "\n"
+    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)"
+    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']))
+
 @task
 def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False):
     print("Relaunch server")
@@ -27,24 +37,19 @@
 
 @task
 def sync_site(version):
-    print(green("sync site with version %s" % version))
+    print(green("sync site and rebuild virtualenv with version %s" % version))
     build_path = build_source(version)
     run('mkdir -p "%s"' % env.remote_path['build_export'])
     res_trans = sync_build(build_path)
     # untar build
     with cd(env.remote_path['build_export']):
         run('tar zxf %s' % res_trans[0])
-    # rebuild virtualenv
-    requirements_path = os.path.join(res_trans[0][0:-7], env.repos[env.key]['requirements'])
-    do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version'])
-    # add setting path to virtualenv
-    ext_path = "import sys; sys.__plen = len(sys.path)\n"
-    for l in env.remote_path.get('pythonpath', []):
-        ext_path += l + "\n"
-    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)"
-    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']))
+
+    do_create_virtualenv(res_trans[0][0:-7])
+
     # install build
     install_build(res_trans[0], env.remote_path['virtualenv'])
+
     # remove build + untared folder
     run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
     clean_export_folder(env.remote_path['build_export'])
@@ -52,38 +57,28 @@
 
 @task
 def create_virtualenv(version):
-    print(green("create virtualenv with version %s" % version))
-    export_path = export_version(web=version)
-    export_path_web = os.path.join(export_path,'web')
-    venv_remote_export_path = ""
-    try:
-        virtualenv_path = os.path.join(export_path_web, "virtualenv")
+    build_path = build_source(version)
+    run('mkdir -p "%s"' % env.remote_path['build_export'])
+    res_trans = sync_build(build_path)
+    # untar build
+    with cd(env.remote_path['build_export']):
+        run('tar zxf %s' % res_trans[0])
 
-        venv_remote_export_path = os.path.join(env.remote_path['venv_export'], env.export_prefix, version,"virtualenv")
-        rsync_export(virtualenv_path, venv_remote_export_path, env.rsync_filters['venv'])
-        do_create_virtualenv(venv_remote_export_path, env.remote_path['virtualenv'])
-    finally:
-        clean_export_folder(export_path)
-        if venv_remote_export_path:
-            clean_rsync_folder(venv_remote_export_path)
+    do_create_virtualenv(res_trans[0][0:-7])
+
+    run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7]))
+    clean_export_folder(env.remote_path['build_export'])
 
-if len(env.repos) > 1:
-    @task
-    def sync_platform(version):
-        print(green("sync platform with version web %s" % (version)))
-        export_path = export_version(web=version)
-
-        export_path_web = os.path.join(export_path,'web')
-        do_sync_web(version, export_path_web)
+@task
+def sync_site_module(version):
+    print(green("sync site with version %s" % version))
+    build_path = build_source(version)
+    run('mkdir -p "%s"' % env.remote_path['build_export'])
+    res_trans = sync_build(build_path)
+    # install build
+    install_build(res_trans[0], env.remote_path['virtualenv'], env.platform_web_module)
 
-        comp_versions = get_comp_versions_dict(export_path_web)
-
-        for key in [k for k in env.repos if k != 'web']:
-            export_path_key = export_version(**{key: comp_versions[key]})
-            export_path_comp = os.path.join(export_path_key, key)
-            do_sync_comp(key, export_path_comp)
-            clean_export_folder(export_path_key)
-
-        create_config(export_path_web)
-        clean_export_folder(export_path)
-        relaunch_server()
+    # remove build + untared folder
+    run('rm -fr "%s"' % (res_trans[0]))
+    clean_export_folder(env.remote_path['build_export'])
+    relaunch_server()