diff -r 9e29d68d48f1 -r fb450f78bfd1 sbin/sync/fabfile.py --- a/sbin/sync/fabfile.py Fri Aug 24 17:44:08 2012 +0200 +++ b/sbin/sync/fabfile.py Thu Aug 30 01:15:16 2012 +0200 @@ -22,13 +22,26 @@ def do_export_version(path, version): print("Export version %s"%str(version)) - - #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 get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, settings_key): + activate_path = os.path.join(remotevirtualenvpath, "bin/activate") + res = "" + with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): + tempfilepath = run("mktemp --tmpdir ldtplatform.XXXXXX") + with settings(warn_only=True): + run("echo \"import os\" > %s" % (tempfilepath)) + map(lambda str: run("echo \"%s\" >> %s" % (str, tempfilepath)), + ["os.environ.setdefault('DJANGO_SETTINGS_MODULE', '%s.settings')" % (platform_web_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)) @@ -46,63 +59,15 @@ print("clean rsync folder %s" % remotepath) run("rm -fr \"%s\"" % remotepath) -def build_src(path): - print("Build source dist at %s" % path) - f = None - try: - f, pathname, description = imp.find_module("setup", [path]) - print(" 2 Build source dist at %s" % path) - setup_mod = imp.load_module("setup", f, pathname, description) - print(" 3 Build source dist at %s" % path) - 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) - f = None - try: - f, pathname, description = imp.find_module("ldt", [path]) - ldt_mod = imp.load_module("ldt", f, pathname, description) - finally: - if f: - f.close() - version = ldt_mod.VERSION - version_str = ldt_mod.get_version() - - return (version, version_str) - - -def sync_build(path): - print("Sync build %s" % path) - with cd(env.remote_ldt_base_path): - filename = os.path.basename(path) - res_trans = put(path, os.path.join(env.remote_ldt_base_path, filename)) - print("Sync build %s to %s" % (path,repr(res_trans))) - return res_trans - -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) - -def collectstatic(remotepath, remotevirtualenvpath): +def collectstatic(remotepath, remotevirtualenvpath, platform_web_module): print("Collect static in %s with %s" % (remotepath, remotevirtualenvpath)) + remotestaticsitepath = get_remote_env(remotepath, remotevirtualenvpath, platform_web_module, "STATIC_ROOT") 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") + #remocve old files optio -c of collect static fail ! + run("rm -fr \"%s\"" % (remotestaticsitepath)) + run("python manage.py collectstatic --noinput") def create_config(export_path): print("Create config from %s" % (export_path,)) @@ -161,26 +126,8 @@ run("python project-boot.py \"%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")) - -def do_sync_ldt(version, export_path): - print("do_sync_ldt with version %s and path %s" % (version,export_path)) - src_path = export_path + "/src/ldt" - build_src(src_path) - (_,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) - 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)) web_path = os.path.join(export_path,"web/") @@ -197,10 +144,11 @@ run("mkdir -p \"%s\"" % folder_path) run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path)) run("chmod -R -c g+w \"%s\"" % folder_path) - -def relaunch_server(): +@task +def relaunch_server(do_collectstatic=True): print("Relaunch server") - collectstatic(env.remote_web_path, env.remote_virtualenv_path) + if do_collectstatic: + collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module) check_folder_access() sudo(env.web_relaunch_cmd, shell=False) @@ -212,14 +160,6 @@ create_config(export_path) clean_export_folder(export_path) relaunch_server() - -@task -def sync_ldt(version): - print(green("sync ldt with version %s" % version)) - export_path = export_version(version) - do_sync_ldt(version, export_path) - clean_export_folder(export_path) - relaunch_server() @task def update_lib(version, package): @@ -237,16 +177,7 @@ 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)) - export_path = export_version(version) - do_sync_ldt(version, export_path) - do_sync_web(version, export_path) - create_config(export_path) - clean_export_folder(export_path) - relaunch_server() + @task def create_virtualenv(version):