--- a/sbin/sync/fabfile.py Thu Jun 14 10:18:38 2012 +0200
+++ b/sbin/sync/fabfile.py Thu Jun 14 15:01:50 2012 +0200
@@ -1,6 +1,8 @@
from fabric.api import task, run, local, env, cd, put, prefix, sudo
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 mercurial import commands, ui, hg, cmdutil
import imp
import os, os.path
@@ -99,10 +101,40 @@
def collectstatic(remotepath, remotevirtualenvpath):
print("Collect static 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(os.path.join(remotepath, env.platform_web_module)):
+ with prefix("source \"%s\"" % activate_path), prefix("export PYTHONPATH=\"%s\"" % remotepath), cd(remotepath):
run("python manage.py collectstatic --noinput")
-
+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,
+ 'web_url': env.web_url,
+ 'stream_url': env.stream_url,
+ 'stream_src_prefix': env.stream_src_prefix,
+ 'ffmpeg_path': env.ffmpeg_path,
+ 'db_engine': env.db_engine,
+ 'db_name': env.db_name,
+ 'db_user': env.db_user,
+ 'db_password': env.db_password,
+ 'db_host': env.db_host,
+ 'db_port': env.db_port,
+ 'log_file': env.log_file,
+ 'index_path': env.index_path,
+ 'google_analytics_code': env.google_analytics_code,
+ 'email_use_tls': env.email_use_tls,
+ 'email_host': env.email_host,
+ 'email_host_user': env.email_host_user,
+ '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))
@@ -134,6 +166,10 @@
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)
@@ -142,6 +178,7 @@
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/")
@@ -151,12 +188,26 @@
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
+ for folder_path in env.folders:
+ if not os.path.isabs(folder_path):
+ folder_path = env.remote_web_path.rstrip("/")+ "/" + folder_path
+ with settings(warn_only=True):
+ if not exists(folder_path):
+ run("mkdir -p \"%s\"" % folder_path)
+ run("chown -R -c :%s \"%s\"" % (env.web_group, folder_path))
+ run("chown -R -c g+w \"%s\"" % folder_path)
@task
def sync_web(version):
print(green("sync web with version %s" % version))
export_path = export_version(version)
- do_sync_web(version, export_path)
+ do_sync_web(version, export_path)
+ check_folder_access()
+ create_config(export_path)
clean_export_folder(export_path)
relaunch_server()
@@ -166,14 +217,33 @@
export_path = export_version(version)
do_sync_ldt(version, export_path)
clean_export_folder(export_path)
- relaunch_server()
-
+ 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))
export_path = export_version(version)
do_sync_ldt(version, export_path)
do_sync_web(version, export_path)
+ check_folder_access()
+ create_config(export_path)
clean_export_folder(export_path)
relaunch_server()