add create config
authorymh <ymh.work@gmail.com>
Wed, 13 Jun 2012 00:54:46 +0200
changeset 69 8a0df65c065c
parent 68 80c372a0485e
child 70 44474052a336
add create config
sbin/sync/config.py.tmpl
sbin/sync/fabfile.py
web/tralalere/config.py.tmpl
--- a/sbin/sync/config.py.tmpl	Tue Jun 12 18:37:23 2012 +0200
+++ b/sbin/sync/config.py.tmpl	Wed Jun 13 00:54:46 2012 +0200
@@ -27,3 +27,30 @@
     "+ core",
 ]
 env.web_relaunch_cmd = "supervisorctl restart platform"
+
+# env variables for config file
+ 
+env.base_url = "/tralalere/"
+env.web_url = "http://exp.iri.centrepompidou.fr"
+env.stream_url = "rtmp://media.iri.centrepompidou.fr/ddc_player/"
+
+env.stream_src_prefix = ""
+env.ffmpeg_path = ""
+
+env.db_engine = 'django.db.backends.postgresql_psycopg2'
+env.db_name = 'tralalere'
+env.db_user = 'iri'
+env.db_password = ''
+env.db_host = 'sql.iri.centrepompidou.fr'
+env.db_port = 5432
+
+env.log_file = env.remote_web_path + '/log/log.txt'
+env.index_path = env.remote_web_path + '/index/'
+
+env.google_analytics_code = ""
+
+env.email_use_tls = True
+env.email_host = ""
+env.email_host_user = ""
+env.email_host_user = ""
+env.email_port = ""
\ No newline at end of file
--- a/sbin/sync/fabfile.py	Tue Jun 12 18:37:23 2012 +0200
+++ b/sbin/sync/fabfile.py	Wed Jun 13 00:54:46 2012 +0200
@@ -1,6 +1,7 @@
 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 mercurial import commands, ui, hg, cmdutil
 import imp
 import os, os.path
@@ -102,7 +103,37 @@
     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,
+     'base_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))
@@ -156,7 +187,8 @@
 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)
+    create_config(export_path)    
     clean_export_folder(export_path)
     relaunch_server()
 
--- a/web/tralalere/config.py.tmpl	Tue Jun 12 18:37:23 2012 +0200
+++ b/web/tralalere/config.py.tmpl	Wed Jun 13 00:54:46 2012 +0200
@@ -4,17 +4,19 @@
 
 SITE_ID = 1
 
-BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"
-BASE_URL = '/~ymh/tralalere/'
-WEB_URL = 'http://localhost'
+#BASE_DIR = os.path.dirname(os.path.abspath(__file__)).rstrip("/")+"/"
+BASE_DIR = '%(base_dir)s'
+BASE_URL = '%(base_url)s'
+WEB_URL = '%(web_url)s'
 
 
-STREAM_SRC_PREFIX = ""
+STREAM_SRC_PREFIX = "%(stream_src_prefix)s"
 
 BASE_STATIC_URL = BASE_URL + 'static/' 
 BASE_STATIC_ROOT = os.path.abspath(BASE_DIR + "../static/").rstrip("/")+"/"
 
-STREAM_URL = "rtmp://media.iri.centrepompidou.fr/ddc_player/"
+#STREAM_URL = "rtmp://media.iri.centrepompidou.fr/ddc_player/"
+STREAM_URL = '%(stream_url)'
 
 
 # Absolute path to the directory that holds media.
@@ -28,7 +30,7 @@
 STATIC_ROOT = BASE_STATIC_ROOT + "site/"
 
 # PATH to the ffmpeg executable, used to know automatically the media file duration 
-FFMPEG_PATH = ""
+FFMPEG_PATH = "%(ffmpeg_path)s"
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
@@ -45,25 +47,38 @@
 ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
 LDT_MEDIA_PREFIX = STATIC_URL + 'ldt/'
 
+#DATABASES = {
+#    'default': {
+#        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+#        'NAME': 'tralalere',                      # Or path to database file if using sqlite3.
+#        'USER': 'iri',                      # Not used with sqlite3.
+#        'PASSWORD': 'iri',                  # Not used with sqlite3.
+#        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
+#        'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
+#    }
+#}
+
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': 'tralalere',                      # Or path to database file if using sqlite3.
-        'USER': 'iri',                      # Not used with sqlite3.
-        'PASSWORD': 'iri',                  # Not used with sqlite3.
-        'HOST': 'localhost',                      # Set to empty string for localhost. Not used with sqlite3.
-        'PORT': '5432',                      # Set to empty string for default. Not used with sqlite3.
+        'ENGINE': '%(db_engine)s', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+        'NAME': '%(db_name)s',                      # Or path to database file if using sqlite3.
+        'USER': '%(db_user)s',                      # Not used with sqlite3.
+        'PASSWORD': '%(db_password)s',                  # Not used with sqlite3.
+        'HOST': '%(db_host)s',                      # Set to empty string for localhost. Not used with sqlite3.
+        'PORT': '%(db_port)d',                      # Set to empty string for default. Not used with sqlite3.
     }
 }
 
+
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
-LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../log/log.txt"))
+#LOG_FILE = os.path.abspath(os.path.join(BASE_DIR,"../log/log.txt"))
+LOG_FILE = '%(log_file)s'
 LOG_LEVEL = logging.DEBUG
 
-INDEX_PATH = os.path.abspath(BASE_DIR + "../index/")
-
+#INDEX_PATH = os.path.abspath(BASE_DIR + "../index/")
+INDEX_PATH = '%(index_path)s'
 
 ADMINS = (
     # ('Your Name', 'your_email@domain.com'),
@@ -71,13 +86,20 @@
 
 MANAGERS = ADMINS
 
-GOOGLE_ANALYTICS_CODE = 'test'
+GOOGLE_ANALYTICS_CODE = '%(google_analytics_code)s'
 
-EMAIL_USE_TLS = True
-EMAIL_HOST = 'smtp.gmail.com'
-EMAIL_HOST_USER = 'iri.ddc@gmail.com'
-EMAIL_HOST_PASSWORD = 'ddciripompidou'
-EMAIL_PORT = 587 
+#EMAIL_USE_TLS = True
+#EMAIL_HOST = 'smtp.gmail.com'
+#EMAIL_HOST_USER = 'iri.ddc@gmail.com'
+#EMAIL_HOST_PASSWORD = ''
+#EMAIL_PORT = 587 
+
+EMAIL_USE_TLS = %(email_use_tls)s
+EMAIL_HOST = '%(email_host)s'
+EMAIL_HOST_USER = '%(email_host_user)s'
+EMAIL_HOST_PASSWORD = '%(email_host_user)s'
+EMAIL_PORT = %(email_port)d 
+
 
 ACCOUNT_ACTIVATION_DAYS = 7
 REGISTRATION_OPEN = False