# HG changeset patch # User ymh # Date 1579641100 -3600 # Node ID 900b29a370aea7b6416d0eda66ac323716b9bad0 # Parent 04db1cae7afc08c5cb4853226a5b214135ee94f4 Force the use of https for the pypi index when installing the server dependencies. diff -r 04db1cae7afc -r 900b29a370ae sbin/sync/fabfile.py --- a/sbin/sync/fabfile.py Tue Jan 21 18:12:38 2020 +0100 +++ b/sbin/sync/fabfile.py Tue Jan 21 22:11:40 2020 +0100 @@ -2,7 +2,7 @@ from fabric.colors import green from fabric.contrib.project import rsync_project from fabric.contrib.files import exists, upload_template -from fabric.context_managers import settings +from fabric.context_managers import settings from mercurial import commands, ui, hg, cmdutil import imp import os, os.path @@ -22,30 +22,30 @@ def do_export_version(path, version): print("Export version %s"%str(version)) - - #hgui = ui.ui() + + #hgui = ui.ui() #repo = hg.repository(hgui, cmdutil.findrepo(os.getcwd())) #commands.archive(hgui, repo, path, rev=str(version)) - + local("hg archive -r \'%s\' \"%s\"" % (str(version),path)) print("Export version %s done"%str(version)) - + def rsync_export(path, remotepath, filters): print("Rsync %s to %s",(path,remotepath)) - + if filters: filter_option_str = " ".join(["--filter \"%s\"" % (f) for f in filters]) else: filter_option_str ="" - + 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 build_src(path): print("Build source dist at %s" % path) f = None @@ -57,11 +57,11 @@ finally: if f: f.close() - + setup_mod.launch_setup("setup.py", ['sdist']) - + print("Build source dist at %s done" % path) - + def get_src_version(path): print("get src version at %s" % path) @@ -74,9 +74,9 @@ f.close() version = ldt_mod.VERSION version_str = ldt_mod.get_version() - - return (version, version_str) - + + return (version, version_str) + def sync_build(path): print("Sync build %s" % path) @@ -89,12 +89,12 @@ def remove_build(path): print("remove build build %s" % path) run("rm \"%s\"" % path) - + def install_build(remotepath, remotevirtualenvpath): print("Install build %s in %s" % (remotepath, remotevirtualenvpath)) activate_path = os.path.join(remotevirtualenvpath, "bin/activate") - + with prefix("source %s" % activate_path): run("pip install \"%s\"" % remotepath) @@ -103,13 +103,13 @@ activate_path = os.path.join(remotevirtualenvpath, "bin/activate") with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): run("python manage.py collectstatic -c --noinput") - -def create_config(export_path): + +def create_config(export_path): print("Create config from %s" % (export_path,)) remotepath = env.remote_web_path remote_config_path = os.path.join(remotepath, env.platform_web_module, "config.py") template_path = os.path.join(export_path, "web", env.platform_web_module, "config.py.tmpl") - + context = { 'base_dir': os.path.join(remotepath, env.platform_web_module).rstrip("/")+"/", 'base_url': env.base_url, @@ -132,18 +132,18 @@ 'email_host_user': env.email_host_user, 'email_port': env.email_port, } - + if not exists(remote_config_path, verbose=True): upload_template(template_path, remote_config_path, context=context) def export_version(version): print("export version %s" % str(version)) - + export_path = get_export_path(version) - + clean_export_folder(export_path) do_export_version(export_path,version) - + return export_path def do_create_virtualenv(remote_venv_export_path, remotevirtualenvpath): @@ -158,7 +158,7 @@ run("python create_python_env.py") run("python project-boot.py --unzip-setuptools --no-site-packages --clear --type-install=local \"%s\"" % remotevirtualenvpath) with prefix("source \"%s\"" % activate_path): - run("pip install -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt")) + run("pip install -i https://pypi.python.org/simple -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt")) def do_sync_ldt(version, export_path): print("do_sync_ldt with version %s and path %s" % (version,export_path)) @@ -167,13 +167,13 @@ (_,version_str) = get_src_version(src_path) build_path = os.path.join(src_path,"dist","ldt-%s.tar.gz" % version_str) sync_install_build(build_path) - + def sync_install_build(build_path): res_trans = None try: res_trans = sync_build(build_path) - install_build(res_trans[0], env.remote_virtualenv_path) + install_build(res_trans[0], env.remote_virtualenv_path) finally: if res_trans: remove_build(res_trans[0]) @@ -181,14 +181,14 @@ def do_sync_web(version, export_path): print("do_sync_web with version %s and path %s" % (version,export_path)) - web_path = os.path.join(export_path,"web/") - rsync_export(web_path, env.remote_web_path, env.web_rsync_filters) + web_path = os.path.join(export_path,"web/") + rsync_export(web_path, env.remote_web_path, env.web_rsync_filters) def relaunch_server(): print("Relaunch server") collectstatic(env.remote_web_path, env.remote_virtualenv_path) sudo(env.web_relaunch_cmd, shell=False) - + def check_folder_access(): print("Check folder access") # get remote user @@ -218,24 +218,24 @@ do_sync_ldt(version, export_path) clean_export_folder(export_path) relaunch_server() - + @task def update_lib(version, package): print(green("update ldt with version %s" % version)) export_path = export_version(version) lib_path = os.path.join(export_path, "virtualenv", "res", "lib") - + f, pathname, description = imp.find_module("patch", [lib_path]) patch = imp.load_module("patch", f, pathname, description) f, pathname, description = imp.find_module("lib_create_env", [lib_path]) lib_create_env = imp.load_module("lib_create_env", f, pathname, description) - + package_path = os.path.join(export_path, "virtualenv", "res", "src", lib_create_env.URLS[package]['local']) - + sync_install_build(package_path) clean_export_folder(export_path) relaunch_server() - + @task def sync_platform(version): print(green("sync platform with version %s" % version)) @@ -254,7 +254,7 @@ venv_remote_export_path = "" try: virtualenv_path = os.path.join(export_path, "virtualenv") - + venv_remote_export_path = os.path.join(env.remote_venv_export_path, env.export_prefix, version,"virtualenv") rsync_export(virtualenv_path, venv_remote_export_path, env.venv_rsync_filters) do_create_virtualenv(venv_remote_export_path, env.remote_virtualenv_path)