diff -r b232a3a2f9fc -r 4b8a549d6399 sbin/sync/fabfile.py --- a/sbin/sync/fabfile.py Thu Oct 18 18:12:20 2012 +0200 +++ b/sbin/sync/fabfile.py Thu Oct 18 18:56:35 2012 +0200 @@ -66,6 +66,13 @@ #remocve old files optio -c of collect static fail ! run("rm -fr \"%s\"" % (remotestaticsitepath)) run("python manage.py collectstatic --noinput") + +def migrate(remotepath, remotevirtualenvpath, platform_web_module): + print("migrate in %s with %s" % (remotepath, remotevirtualenvpath)) + activate_path = os.path.join(remotevirtualenvpath, "bin/activate") + with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath): + #remocve old files optio -c of collect static fail ! + run("python manage.py migrate --noinput") def create_config(export_path): print("Create config from %s" % (export_path,)) @@ -129,7 +136,38 @@ 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,env.local_folders.get("web","web").rstrip("/")+"/") - rsync_export(web_path, env.remote_web_path, env.web_rsync_filters) + rsync_export(web_path, env.remote_web_path, env.web_rsync_filters) + +def remove_lib(path): + print("remove build build %s" % path) + run("rm \"%s\"" % path) + +def install_lib(remotepath, remotevirtualenvpath): + print("Install lib %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 sync_lib(path): + print("Sync build %s" % path) + run("mkdir -p \"%s\"" % env.remote_venv_export_path) + with cd(env.remote_venv_export_path): + filename = os.path.basename(path) + dest_path = os.path.join(env.remote_venv_export_path, filename) + res_trans = put(path, dest_path) + print("Sync build %s to %s" % (path,repr(res_trans))) + return res_trans + +def sync_install_lib(lib_path): + res_trans = None + try: + res_trans = sync_lib(lib_path) + install_lib(res_trans[0], env.remote_virtualenv_path) + finally: + if res_trans: + remove_lib(res_trans[0]) + def check_folder_access(): print("Check folder access") @@ -143,11 +181,13 @@ run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path)) run("chmod -R -c g+w \"%s\"" % folder_path) @task -def relaunch_server(do_collectstatic=True): +def relaunch_server(do_collectstatic=True, do_migrate=True): print("Relaunch server") check_folder_access() if do_collectstatic: collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module) + if do_migrate: + migrate(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module) sudo(env.web_relaunch_cmd, shell=False) @task @@ -172,7 +212,7 @@ package_path = os.path.join(export_path, env.local_folders.get("virtualenv","virtualenv"), "res", "src", lib_create_env.URLS[package]['local']) - sync_install_build(package_path) + sync_install_lib(package_path) clean_export_folder(export_path) relaunch_server()