sbin/sync/fabfile.py
changeset 50 4dd7fa373ed6
parent 27 4b8a549d6399
child 82 fa141523769a
--- a/sbin/sync/fabfile.py	Thu Nov 15 12:36:03 2012 +0100
+++ b/sbin/sync/fabfile.py	Fri Nov 16 00:56:34 2012 +0100
@@ -72,36 +72,16 @@
     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")
+        run("python manage.py syncdb --migrate --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, env.local_folders.get("web","web"), env.platform_web_module, "config.py.tmpl")
+def create_config(export_path, key):    
+    print("Create config from %s with key %s" % (export_path,key))
+    remotepath = env.remote_web_path[key]
+    remote_config_path = os.path.join(remotepath, env.web_module[key], "config.py")
+    template_path = os.path.join(export_path, env.local_folders[key], env.web_module[key], "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,
-     '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,
-     'forbidden_stream_url': env.forbidden_stream_url,
-    }
+    context = env.config[key]
+    context['base_dir'] = os.path.join(remotepath, env.web_module[key]).rstrip("/")+"/"
     
     if not exists(remote_config_path, verbose=True):
         upload_template(template_path, remote_config_path, context=context)
@@ -133,10 +113,10 @@
         run("pip install -r \"%s\"" % os.path.join(remote_venv_export_path,"virtualenv","web","res","srvr_requirements.txt"))
         
 
-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)
+def do_sync_web(version, export_path, key):
+    print("do_sync_web with version %s and path %s and key %s" % (version,export_path, key))
+    web_path = os.path.join(export_path,env.local_folders[key].rstrip("/")+"/") 
+    rsync_export(web_path, env.remote_web_path[key], env.web_rsync_filters[key])
 
 def remove_lib(path):
     print("remove build build %s" % path)
@@ -169,35 +149,36 @@
             remove_lib(res_trans[0])
 
     
-def check_folder_access():
+def check_folder_access(key):
     print("Check folder access")
     # get remote user
-    for folder_path in env.folders:
+    for folder_path in env.folders[key]:
         if not os.path.isabs(folder_path):
-            folder_path = env.remote_web_path.rstrip("/")+ "/" + folder_path
+            folder_path = env.remote_web_path[key].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("chmod -R -c g+w \"%s\"" % folder_path)
 @task
-def relaunch_server(do_collectstatic=True, do_migrate=True):
+def relaunch_server(key,do_collectstatic=True, do_migrate=True):
     print("Relaunch server")
-    check_folder_access()
+    check_folder_access(key)
     if do_collectstatic:
-        collectstatic(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module)
+        collectstatic(env.remote_web_path[key], env.remote_virtualenv_path, env.web_module[key])
     if do_migrate:
-        migrate(env.remote_web_path, env.remote_virtualenv_path, env.platform_web_module)
-    sudo(env.web_relaunch_cmd, shell=False)
+        migrate(env.remote_web_path[key], env.remote_virtualenv_path, env.web_module[key])
+    sudo(env.relaunch_cmd[key], shell=False)
+
 
 @task
-def sync_web(version):
+def sync_web(version, key):
     print(green("sync web with version %s" % version))
     export_path = export_version(version)
-    do_sync_web(version, export_path)
-    create_config(export_path)
+    do_sync_web(version, export_path, key)
+    create_config(export_path, key)
     clean_export_folder(export_path)
-    relaunch_server()
+    relaunch_server(key)
     
 @task
 def update_lib(version, package):
@@ -232,3 +213,20 @@
         clean_export_folder(export_path)
         if venv_remote_export_path:
             clean_rsync_folder(venv_remote_export_path)
+
+
+#sync hp
+# sync files
+# create virtualenv
+# create config
+# syncdb + migrate
+# collectstatic
+# relaunch web
+
+#sync ldt
+# sync files
+# create virtualenv
+# create config
+# syncdb + migrate
+# collectstatic
+# relaunch web