sbin/sync/fabfile.py
changeset 759 6d341beaf632
parent 694 1497bbb6485e
child 761 08f962473d45
--- a/sbin/sync/fabfile.py	Mon Aug 27 02:21:38 2012 +0200
+++ b/sbin/sync/fabfile.py	Wed Aug 29 23:38:49 2012 +0200
@@ -22,13 +22,27 @@
 
 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 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))
@@ -98,11 +112,14 @@
     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,))
@@ -197,10 +214,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)