first iteration of migration to fabric 2 / python 3 default
authorymh <ymh.work@gmail.com>
Tue, 23 Oct 2018 11:32:03 +0200
changeset 32 800b7b8aa439
parent 31 1da4c3724486
first iteration of migration to fabric 2 / python 3
.hgignore
src/fablib/__init__.py
src/fablib/core.py
src/requirements.txt
--- a/.hgignore	Mon Jun 11 15:02:51 2018 +0200
+++ b/.hgignore	Tue Oct 23 11:32:03 2018 +0200
@@ -6,4 +6,5 @@
 syntax: regexp
 ^src/MANIFEST$
 syntax: regexp
-^src/dist$
\ No newline at end of file
+^src/dist$
+^src/fablib.egg-info
--- a/src/fablib/__init__.py	Mon Jun 11 15:02:51 2018 +0200
+++ b/src/fablib/__init__.py	Tue Oct 23 11:32:03 2018 +0200
@@ -1,16 +1,20 @@
 
-from .core import (check_folder_access, migrate, collectstatic, do_relaunch_server,
-                   export_version, do_sync_web, create_config, clean_export_folder,
-                   sync_install_build, do_create_virtualenv, clean_rsync_folder, rsync_export,
-                   do_sync_comp, get_comp_versions_dict, SyncComp, get_src_version, sync_build,
-                   install_build, do_create_virtualenv_requirement, build_src)
+# from .core import (check_folder_access, migrate, collectstatic, do_relaunch_server,
+#                    export_version, do_sync_web, create_config, clean_export_folder,
+#                    sync_install_build, do_create_virtualenv, clean_rsync_folder, rsync_export,
+#                    do_sync_comp, get_comp_versions_dict, SyncComp, get_src_version, sync_build,
+#                    install_build, do_create_virtualenv_requirement, build_src)
+
+from .core import (export_version, build_src, get_src_version, sync_build, do_create_virtualenv_requirement)
 
-__all__ = ["check_folder_access", "migrate", "collectstatic", "do_sync_comp",
-           "export_version", "do_sync_web", "create_config", "clean_export_folder",
-           "relaunch_server", "do_sync_ldt", "sync_install_build", "do_create_virtualenv",
-           "clean_rsync_folder", "rsync_export", "get_comp_versions_dict", "SyncComp",
-           "get_src_version", "sync_build", "install_build", "do_create_virtualenv_requirement",
-           "build_src"]
+
+
+# __all__ = ["check_folder_access", "migrate", "collectstatic", "do_sync_comp",
+#            "export_version", "do_sync_web", "create_config", "clean_export_folder",
+#            "relaunch_server", "do_sync_ldt", "sync_install_build", "do_create_virtualenv",
+#            "clean_rsync_folder", "rsync_export", "get_comp_versions_dict", "SyncComp",
+#            "get_src_version", "sync_build", "install_build", "do_create_virtualenv_requirement",
+#            "build_src"]
 
 VERSION = (0, 1, 0, "dev", 0)
 
@@ -22,7 +26,7 @@
     if VERSION[3:] == ('alpha', 0):
         version = '%s.pre-alpha' % version
     elif VERSION[3] != 'final':
-        version = '%s.%s.%s' % (version, VERSION[3], VERSION[4])
+        version = '%s.%s%s' % (version, VERSION[3], VERSION[4])
     return version
 
 
--- a/src/fablib/core.py	Mon Jun 11 15:02:51 2018 +0200
+++ b/src/fablib/core.py	Tue Oct 23 11:32:03 2018 +0200
@@ -4,27 +4,28 @@
 
 @author: ymh
 '''
-from fabric.api import run, local, env, cd, put, prefix, sudo, lcd
-from fabric.colors import green
-from fabric.context_managers import settings
-from fabric.contrib.files import exists, upload_template
-from fabric.contrib.project import rsync_project
-from fabric.tasks import Task
+# from fabric.api import run, local, env, cd, put, prefix, sudo, lcd
+# from fabric.colors import green
+# from fabric.context_managers import settings
+# from fabric.contrib.files import exists, upload_template
+# from fabric.contrib.project import rsync_project
+# from fabric.tasks import Task
+from fabric import Connection
 import imp
 import os.path
 import re
 import shutil
 import sys
-import urlparse
+import urllib.parse
 
 
-__all__ = ["check_folder_access", "migrate", "collectstatic", "do_relaunch_server",
-           "export_version", "do_sync_web", "create_config", "clean_export_folder",
-           "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export",
-           "do_sync_comp", "get_comp_versions_dict", "SyncComp", "get_src_version", "sync_build",
-           "install_build", "do_create_virtualenv_requirement", "build_src"]
+# __all__ = ["check_folder_access", "migrate", "collectstatic", "do_relaunch_server",
+#            "export_version", "do_sync_web", "create_config", "clean_export_folder",
+#            "sync_install_build", "do_create_virtualenv", "clean_rsync_folder", "rsync_export",
+#            "do_sync_comp", "get_comp_versions_dict", "SyncComp", "get_src_version", "sync_build",
+#            "install_build", "do_create_virtualenv_requirement", "build_src"]
 
-def get_export_path(version):
+def get_export_path(env, version):
     base_path = os.path.join(env.base_export_path,env.export_prefix).rstrip("/")
     return os.path.expanduser(base_path) + "_%s" % (str(version))
 
@@ -33,80 +34,81 @@
     if os.path.isdir(path):
         shutil.rmtree(path, ignore_errors=True)
 
-def do_export_version(path, **export_keys):
-    print("Export version %s : %s " % (path,repr(export_keys)))
+def do_export_version(c, path, **export_keys):
+    print("Export version %s : %s" % (path,repr(export_keys)))
+
+    env = c.env
 
     for export_key, version in export_keys.items():
         export_path = os.path.join(path,export_key)
 
         repo_url = env.repos[export_key]['repo']
-        url_part = urlparse.urlparse(repo_url)
+        url_part = urllib.parse.urlparse(repo_url)
         if url_part.scheme or url_part.netloc:
             # this is a remote repo. Let's clone first
-            clone_path = os.path.join(path,'clone',export_keys)
+            clone_path = os.path.join(path,'clone',export_keys[export_key])
             os.makedirs(clone_path)
 
-            scm = "hg"
-            with settings(warn_only=True):
-                output = local('git ls-remote \"%s\"' % repo_url)
-                scm = "git" if output.failed else "hg"
+            output = c.run('git ls-remote \"%s\"' % repo_url, warn=True)
+            print("OUTPUT %r" % output)
+            scm = "hg" if output.failed else "git"
             if scm == "hg":
-                output = local("hg clone \"%s\" \"%s\"" % (repo_url,clone_path))
+                output = c.run("hg clone \"%s\" \"%s\"" % (repo_url,clone_path))
             else:
-                local("git clone \"%s\" \"%s\"" % (repo_url,clone_path))
+                c.run("git clone \"%s\" \"%s\"" % (repo_url,clone_path))
         else:
             clone_path = repo_url
 
-        with lcd(clone_path):
+        with c.cd(clone_path):
             # detetct .git or .hg subfolder
             if os.path.exists(os.path.join(clone_path,".git")):
                 os.makedirs(export_path)
                 cmd_str = "git archive \'%s\' | tar -x -C \"%s\""
             else:
                 cmd_str = "hg archive -r \'%s\' \"%s\""
-            local(cmd_str % (str(version),export_path))
+            c.run(cmd_str % (str(version),export_path))
 
     print("Export version %s done"%repr(export_keys))
 
 
-def get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, settings_key, settings_module=''):
-    if not settings_module:
-        settings_module = '%s.%s' % (platform_web_module, 'settings')
-    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
-    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
-        tempfilepath = run("mktemp -t fablib.XXXXXX")
-        with settings(warn_only=True):
-            run("echo \"import os\" > %s" % (tempfilepath))
-            map(lambda str_echo: run("echo \"%s\" >> %s" % (str_echo, tempfilepath)),
-                ["os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s')" % (settings_module),
-                 "from django.conf import settings",
-                 "print(settings.%s)" % (settings_key)])
-            res = run("python < %s" % (tempfilepath))
-        run("rm -f \"%s\"" % (tempfilepath))
-    return res
+# def get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, settings_key, settings_module=''):
+#     if not settings_module:
+#         settings_module = '%s.%s' % (platform_web_module, 'settings')
+#     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
+#     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
+#         tempfilepath = run("mktemp -t fablib.XXXXXX")
+#         with settings(warn_only=True):
+#             run("echo \"import os\" > %s" % (tempfilepath))
+#             map(lambda str_echo: run("echo \"%s\" >> %s" % (str_echo, tempfilepath)),
+#                 ["os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s')" % (settings_module),
+#                  "from django.conf import settings",
+#                  "print(settings.%s)" % (settings_key)])
+#             res = run("python < %s" % (tempfilepath))
+#         run("rm -f \"%s\"" % (tempfilepath))
+#     return res
 
 
 
-def rsync_export(path, remotepath, filters):
-    print("Rsync %s to %s",(path,remotepath))
+# def rsync_export(path, remotepath, filters):
+#     print("Rsync %s to %s",(path,remotepath))
 
-    filter_option_str = "--progress --stats"
-    if filters:
-        filter_option_str += " " + " ".join(["--filter \"%s\"" % (f) for f in filters])
+#     filter_option_str = "--progress --stats"
+#     if filters:
+#         filter_option_str += " " + " ".join(["--filter \"%s\"" % (f) for f in filters])
 
-    run("mkdir -p \"%s\"" % remotepath)
-    rsync_project(remotepath, local_dir=path, extra_opts=filter_option_str, delete=True)
-    print("Rsync %s to %s done",(path,remotepath))
+#     run("mkdir -p \"%s\"" % remotepath)
+#     rsync_project(remotepath, local_dir=path, extra_opts=filter_option_str, delete=True)
+#     print("Rsync %s to %s done",(path,remotepath))
 
-def clean_rsync_folder(remotepath):
-    print("clean rsync folder %s" % remotepath)
-    run("rm -fr \"%s\"" % remotepath)
+# def clean_rsync_folder(remotepath):
+#     print("clean rsync folder %s" % remotepath)
+#     run("rm -fr \"%s\"" % remotepath)
 
-def build_src(path):
+def build_src(c, path):
     print("Build source dist at %s" % path)
     f = None
     sys.path.append(path)
-    current_path = os.getcwdu()
+    current_path = os.getcwd()
     try:
         os.chdir(path)
         try:
@@ -127,27 +129,29 @@
         os.chdir(current_path)
     print("Build source dist at %s done" % path)
 
-def get_version(version):
-    version_str = '%s.%s' % (version[0], version[1])
-    if version[2]:
-        version_str = '%s.%s' % (version_str, version[2])
-    if version[3:] == ('alpha', 0):
-        version_str = '%s pre-alpha' % version_str
-    else:
-        if version[3] != 'final':
-            version_str = '%s %s %s' % (version_str, version[3], version[4])
-    return version_str
+# def get_version(version):
+#     version_str = '%s.%s' % (version[0], version[1])
+#     if version[2]:
+#         version_str = '%s.%s' % (version_str, version[2])
+#     if version[3:] == ('alpha', 0):
+#         version_str = '%s pre-alpha' % version_str
+#     else:
+#         if version[3] != 'final':
+#             version_str = '%s %s %s' % (version_str, version[3], version[4])
+#     return version_str
 
 
-def get_src_version(key, path):
+def get_src_version(c, key, path):
 
     print("get src version for %s at %s" % (key,path))
 
+    env = c.env
+
     mod_name = env.repos[key].get('module', key) or key
 
     f = None
     sys.path.append(path)
-    current_path = os.getcwdu()
+    current_path = os.getcwd()
     os.chdir(path)
     try:
         f, pathname, description = imp.find_module(mod_name, [path])
@@ -177,7 +181,7 @@
     if version is None:
         version = ""
 
-    if not isinstance(version, basestring):
+    if not isinstance(version, str):
         if src_mod and hasattr(src_mod, "get_version"):
             version_str = src_mod.get_version()
         elif isinstance(version, tuple):
@@ -192,205 +196,209 @@
     return (version, version_str)
 
 
-def sync_build(path):
+def sync_build(c, path):
     print("Sync build %s" % path)
-    with cd(env.remote_path['build_export']):
-        filename = os.path.basename(path)
-        res_trans = put(path, os.path.join(env.remote_path['build_export'], filename))
-        print("Sync build %s to %s" % (path,repr(res_trans)))
-        return res_trans
+    env = c.env
+    with Connection(env['hosts'][0]) as host_connection:
+        with host_connection.cd(env.remote_path['build_export']):
+            filename = os.path.basename(path)
+            res_trans = host_connection.put(path, os.path.join(env.remote_path['build_export'], filename))
+            print("Sync build %s to %s" % (path,res_trans.remote))
+            return res_trans
 
-def remove_build(path):
-    print("remove build build %s" % path)
-    run("rm \"%s\"" % path)
+# def remove_build(path):
+#     print("remove build build %s" % path)
+#     run("rm \"%s\"" % path)
 
 
-def install_build(remotepath, remotevirtualenvpath, module_to_uninstall= None):
-    print("Install build %s in %s" % (remotepath, remotevirtualenvpath))
-    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
+# def install_build(remotepath, remotevirtualenvpath, module_to_uninstall= None):
+#     print("Install build %s in %s" % (remotepath, remotevirtualenvpath))
+#     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
 
-    with prefix("source %s" % activate_path):
-        if module_to_uninstall:
-            with settings(warn_only=True):
-                run("pip uninstall -y %s" % module_to_uninstall)
-        run("pip install --no-cache-dir \"%s\"" % remotepath)
+#     with prefix("source %s" % activate_path):
+#         if module_to_uninstall:
+#             with settings(warn_only=True):
+#                 run("pip uninstall -y %s" % module_to_uninstall)
+#         run("pip install --no-cache-dir \"%s\"" % remotepath)
 
-def collectstatic(remotepath, remotevirtualenvpath, platform_web_module, module_settings="", admin_cmd="python manage.py"):
-    print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath))
-    remotestaticsitepath = get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, "STATIC_ROOT", env.settings)
-    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
-    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
-        #remove old files optio -c of collect static fail !
-        run("rm -fr \"%s\"/*" % (remotestaticsitepath))
-        run("%s collectstatic --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
+# def collectstatic(remotepath, remotevirtualenvpath, platform_web_module, module_settings="", admin_cmd="python manage.py"):
+#     print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath))
+#     remotestaticsitepath = get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, "STATIC_ROOT", env.settings)
+#     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
+#     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
+#         #remove old files optio -c of collect static fail !
+#         run("rm -fr \"%s\"/*" % (remotestaticsitepath))
+#         run("%s collectstatic --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
 
-def migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
-    {
-        'syncdb': do_syncdb,
-        'migrate': do_migrate,
-    }.get(getattr(env, 'migrate_method', 'migrate'), do_syncdb)(remotepath, remotevirtualenvpath, module_settings, admin_cmd)
+# def migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
+#     {
+#         'syncdb': do_syncdb,
+#         'migrate': do_migrate,
+#     }.get(getattr(env, 'migrate_method', 'migrate'), do_syncdb)(remotepath, remotevirtualenvpath, module_settings, admin_cmd)
 
-def do_syncdb(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
-    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
-    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
-        run("%s syncdb --migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
+# def do_syncdb(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
+#     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
+#     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
+#         run("%s syncdb --migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
 
 
-def do_migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
-    activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
-    with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
-        run("%s migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
+# def do_migrate(remotepath, remotevirtualenvpath, module_settings="", admin_cmd="python manage.py"):
+#     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
+#     with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
+#         run("%s migrate --noinput %s" % (admin_cmd, "--settings="+module_settings if module_settings else ""))
 
 
-def create_config(export_path):
-    print("Create config from %s" % (export_path,))
-    remotepath = env.remote_path['src']
-    remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py")
-    template_path = os.path.join(export_path, "src", env.platform_web_module, "config.py.tmpl")
+# def create_config(export_path):
+#     print("Create config from %s" % (export_path,))
+#     remotepath = env.remote_path['src']
+#     remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py")
+#     template_path = os.path.join(export_path, "src", env.platform_web_module, "config.py.tmpl")
 
-    context = {
-        'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/",
-        'asctime': '%(asctime)s',
-        'levelname': '%(levelname)s',
-        'message': '%(message)s',
-        'module': '%(module)s',
-    }
-    context.update(env.config['web'])
+#     context = {
+#         'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/",
+#         'asctime': '%(asctime)s',
+#         'levelname': '%(levelname)s',
+#         'message': '%(message)s',
+#         'module': '%(module)s',
+#     }
+#     context.update(env.config['web'])
 
-    if not exists(remote_config_path, verbose=True):
-        upload_template(template_path, remote_config_path, context=context)
+#     if not exists(remote_config_path, verbose=True):
+#         upload_template(template_path, remote_config_path, context=context)
 
-def export_version(**kwargs):
+def export_version(c, **kwargs):
     print("export version %s" % (repr(kwargs)))
 
     export_path = kwargs.get('path', None)
 
     if not export_path:
-        export_path = get_export_path("_".join(["%s_%s" % (k,v) for k,v in kwargs.items()]))
+        export_path = get_export_path(c.env, "_".join(["%s_%s" % (k,v) for k,v in kwargs.items()]))
 
     clean_export_folder(export_path)
 
-    do_export_version(export_path,**kwargs)
+    do_export_version(c, export_path,**kwargs)
 
     return export_path
 
-def do_create_virtualenv(remote_venv_export_path, remotevirtualenvpath):
+def do_create_virtualenv(c, remote_venv_export_path, remotevirtualenvpath):
     print("Create virtualenv export_path : %s - remote venvpath : %s" % (remote_venv_export_path, remotevirtualenvpath))
+    env = c.env
     activate_path = os.path.join(remotevirtualenvpath, "bin/activate")
-    if "remote_baseline_venv" in env and env.remote_baseline_venv:
-        prefix_str = "source \"%s\"" % os.path.join(env.remote_baseline_venv, "bin/activate")
+    if env.get('remote_baseline_venv'):
+        prefix_str = "source \"%s\"" % os.path.join(env.get('remote_baseline_venv'), "bin/activate")
     else:
         prefix_str = "echo"
-    with settings(warn_only=True):
-        run("rm -fr \"%s\"" % remotevirtualenvpath)
-    run("mkdir -p \"%s\"" % remotevirtualenvpath)
-    with prefix(prefix_str), cd(os.path.join(remote_venv_export_path,"virtualenv","web")):
-        run("python create_python_env.py")
-        run("python project-boot.py \"%s\"" % remotevirtualenvpath)
-    with prefix("source \"%s\"" % activate_path):
-        run("pip install --no-cache-dir -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt"))
+    with Connection(env['hosts'][0]) as rconnection:
+        rconnection.run("rm -fr \"%s\"" % remotevirtualenvpath, warn=True)
+        run("mkdir -p \"%s\"" % remotevirtualenvpath)
+        with rconnection.prefix(prefix_str), rconnection.cd(os.path.join(remote_venv_export_path,"virtualenv","web")):
+            rconnection.run("python create_python_env.py")
+            rconnection.run("python project-boot.py \"%s\"" % remotevirtualenvpath)
+        with rconnection.prefix("source \"%s\"" % activate_path):
+            rconnection.run("pip install --no-cache-dir -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt"))
 
-def do_create_virtualenv_requirement(remote_venv_requirement_path, remotevirtualenvpath, python_version = "2"):
+def do_create_virtualenv_requirement(c, remote_venv_requirement_path, remotevirtualenvpath, python_version = "2"):
     print("Create virtualenv export_path : %s - remote venvpath : %s" % (remote_venv_requirement_path, remotevirtualenvpath))
-    with settings(warn_only=True):
-        run("rm -fr \"%s\"" % remotevirtualenvpath)
-    run("mkdir -p \"%s\"" % remotevirtualenvpath)
-    run("virtualenv -p `which python%s` %s" % (python_version, remotevirtualenvpath))
-    with prefix("source \"%s\"" % os.path.join(remotevirtualenvpath, "bin/activate")):
-        run("pip install -r \"%s\"" % remote_venv_requirement_path)
-
+    env = c.env
+    with Connection(env['hosts'][0]) as rconnection:
+        rconnection.sudo("rm -fr \"%s\"" % remotevirtualenvpath, warn=True)
+        rconnection.sudo("mkdir -p \"%s\"" % remotevirtualenvpath)
+        # rconnection.run("virtualenv -p `which python%s` %s" % (python_version, remotevirtualenvpath))
+        rconnection.run("python%s -m venv %s" % (python_version, remotevirtualenvpath))
+        with rconnection.prefix("source \"%s\"" % os.path.join(remotevirtualenvpath, "bin/activate")):
+            rconnection.run("pip install -r \"%s\"" % remote_venv_requirement_path)
 
 
-def do_sync_comp(key, export_path):
-    print("do_sync_comp with  path %s" % (export_path))
+# def do_sync_comp(key, export_path):
+#     print("do_sync_comp with  path %s" % (export_path))
 
-    src_path = os.path.join(export_path,env.repos[key]['src_root'])
-    # find setup.py
-    for root, _, files in os.walk(src_path):
-        if "setup.py" in files:
-            src_path = root
+#     src_path = os.path.join(export_path,env.repos[key]['src_root'])
+#     # find setup.py
+#     for root, _, files in os.walk(src_path):
+#         if "setup.py" in files:
+#             src_path = root
 
-    build_src(src_path)
-    (_,version_str) = get_src_version(key, src_path)
-    build_path = os.path.join(src_path,"dist","%s-%s.tar.gz" % (key,version_str))
-    sync_install_build(build_path, key)
+#     build_src(src_path)
+#     (_,version_str) = get_src_version(key, src_path)
+#     build_path = os.path.join(src_path,"dist","%s-%s.tar.gz" % (key,version_str))
+#     sync_install_build(build_path, key)
 
 
-def sync_install_build(build_path, module_to_uninstall=None):
-    res_trans = None
-    try:
-        res_trans = sync_build(build_path)
-        install_build(res_trans[0], env.remote_path['virtualenv'], module_to_uninstall)
-    finally:
-        if res_trans:
-            remove_build(res_trans[0])
+# def sync_install_build(build_path, module_to_uninstall=None):
+#     res_trans = None
+#     try:
+#         res_trans = sync_build(build_path)
+#         install_build(res_trans[0], env.remote_path['virtualenv'], module_to_uninstall)
+#     finally:
+#         if res_trans:
+#             remove_build(res_trans[0])
 
 
-def do_sync_web(version, export_path):
-    print("do_sync_web with version %s and path %s" % (version,export_path))
-    #sync src
-    src_path = os.path.join(export_path,"src/")
-    rsync_export(src_path, env.remote_path['src'], env.rsync_filters['src'])
+# def do_sync_web(version, export_path):
+#     print("do_sync_web with version %s and path %s" % (version,export_path))
+#     #sync src
+#     src_path = os.path.join(export_path,"src/")
+#     rsync_export(src_path, env.remote_path['src'], env.rsync_filters['src'])
 
 
-def check_folder_access():
-    print("Check folder access")
-    # get remote user
-    for folder_path in env.folders:
-        if not os.path.isabs(folder_path):
-            folder_path = env.remote_path['web'].rstrip("/")+ "/" + folder_path
-            with settings(warn_only=True):
-                if not exists(folder_path):
-                    run("mkdir -p \"%s\"" % folder_path)
-                run("chown -R :%s \"%s\"" % (env.web_group, folder_path))
-                run("chmod -R g+w \"%s\"" % folder_path)
+# def check_folder_access():
+#     print("Check folder access")
+#     # get remote user
+#     for folder_path in env.folders:
+#         if not os.path.isabs(folder_path):
+#             folder_path = env.remote_path['web'].rstrip("/")+ "/" + folder_path
+#             with settings(warn_only=True):
+#                 if not exists(folder_path):
+#                     run("mkdir -p \"%s\"" % folder_path)
+#                 run("chown -R :%s \"%s\"" % (env.web_group, folder_path))
+#                 run("chmod -R g+w \"%s\"" % folder_path)
 
-def get_comp_versions_dict(export_path_web):
-    comp_versions = {}
-    requirement_file_path = os.path.join(export_path_web, 'src', 'requirement.txt')
-    if not os.path.exists(requirement_file_path):
-        return comp_versions
-    with open(requirement_file_path) as f:
-        for line in f:
-            m = re.match('^([\w-]+)\s+\(\s*\=\=\s*([\.\d\w]+)\s*\)', line)
-            if m:
-                key, version_req = m.groups()
-                if "." in version_req:
-                    version_req = "V" + ".".join(["%02d" % (int(s)) if s.isdigit() else s for s in version_req.split(".")])
-                comp_versions[key] = version_req
+# def get_comp_versions_dict(export_path_web):
+#     comp_versions = {}
+#     requirement_file_path = os.path.join(export_path_web, 'src', 'requirement.txt')
+#     if not os.path.exists(requirement_file_path):
+#         return comp_versions
+#     with open(requirement_file_path) as f:
+#         for line in f:
+#             m = re.match('^([\w-]+)\s+\(\s*\=\=\s*([\.\d\w]+)\s*\)', line)
+#             if m:
+#                 key, version_req = m.groups()
+#                 if "." in version_req:
+#                     version_req = "V" + ".".join(["%02d" % (int(s)) if s.isdigit() else s for s in version_req.split(".")])
+#                 comp_versions[key] = version_req
 
-    return comp_versions
+#     return comp_versions
 
-def do_relaunch_server(do_collectstatic, do_migrate, do_check_folder_access):
-    if do_check_folder_access:
-        check_folder_access()
-    if do_migrate:
-        migrate(env.remote_path['src'], env.remote_path['virtualenv'], env.get('settings', ''), env.get('admin_cmd', 'python manage.py'))
-    if do_collectstatic:
-        collectstatic(env.remote_path['src'], env.remote_path['virtualenv'], env.platform_web_module, env.get('settings', ''), env.get('admin_cmd', 'python manage.py'))
-    sudo(env.web_relaunch_cmd, shell=False)
+# def do_relaunch_server(do_collectstatic, do_migrate, do_check_folder_access):
+#     if do_check_folder_access:
+#         check_folder_access()
+#     if do_migrate:
+#         migrate(env.remote_path['src'], env.remote_path['virtualenv'], env.get('settings', ''), env.get('admin_cmd', 'python manage.py'))
+#     if do_collectstatic:
+#         collectstatic(env.remote_path['src'], env.remote_path['virtualenv'], env.platform_web_module, env.get('settings', ''), env.get('admin_cmd', 'python manage.py'))
+#     sudo(env.web_relaunch_cmd, shell=False)
 
 
-class SyncComp(Task):
+# class SyncComp(Task):
 
-    def __init__(self, key):
-        self.key = key
+#     def __init__(self, key):
+#         self.key = key
 
-    def __get_name(self):
-        return "sync_" + self.key
+#     def __get_name(self):
+#         return "sync_" + self.key
 
-    name = property(__get_name)
+#     name = property(__get_name)
 
-    def run(self, version):
-        print(green("sync %s with version %s" % (self.key, version)))
-        export_path_web = export_version(web=version)
-        export_path_web_full = os.path.join(export_path_web,'web')
-        comp_versions = get_comp_versions_dict(export_path_web_full)
+#     def run(self, version):
+#         print(green("sync %s with version %s" % (self.key, version)))
+#         export_path_web = export_version(web=version)
+#         export_path_web_full = os.path.join(export_path_web,'web')
+#         comp_versions = get_comp_versions_dict(export_path_web_full)
 
-        export_path = export_version(**{self.key:comp_versions[self.key]})
-        export_path_full = os.path.join(export_path,self.key)
-        do_sync_comp(self.key, export_path_full)
-        clean_export_folder(export_path)
-        clean_export_folder(export_path_web)
+#         export_path = export_version(**{self.key:comp_versions[self.key]})
+#         export_path_full = os.path.join(export_path,self.key)
+#         do_sync_comp(self.key, export_path_full)
+#         clean_export_folder(export_path)
+#         clean_export_folder(export_path_web)
 
-        do_relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=True)
+#         do_relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=True)
--- a/src/requirements.txt	Mon Jun 11 15:02:51 2018 +0200
+++ b/src/requirements.txt	Tue Oct 23 11:32:03 2018 +0200
@@ -3,3 +3,4 @@
 mercurial
 paramiko
 pycrypto
+blessings