wcsinstd: configure sql access

This commit is contained in:
Frédéric Péters 2013-06-12 17:06:52 +02:00
parent 6b376cfffb
commit 8a3f16cdef
1 changed files with 40 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import string
import cPickle import cPickle
import os import os
import zipfile import zipfile
import subprocess
from urlparse import urlparse from urlparse import urlparse
from cStringIO import StringIO from cStringIO import StringIO
@ -65,18 +66,55 @@ class DeployInstance(object):
wcs_cfg = cPickle.load(file(os.path.join(self.collectivity_install_dir, 'config.pck'))) wcs_cfg = cPickle.load(file(os.path.join(self.collectivity_install_dir, 'config.pck')))
else: else:
wcs_cfg = {} wcs_cfg = {}
# TODO: there are some settings to change in wcs_cfg
# (like the name of the database)
has_sql = self.make_sql_config(wcs_cfg)
self.make_sso_config(wcs_cfg) self.make_sso_config(wcs_cfg)
self.make_site_options() self.make_site_options()
cPickle.dump(wcs_cfg, file(config_file, 'w')) cPickle.dump(wcs_cfg, file(config_file, 'w'))
if has_sql:
self.make_sql_tables(wcs_cfg)
self.make_apache_vhost() self.make_apache_vhost()
self.reload_apache() self.reload_apache()
def make_sql_config(self, wcs_cfg):
if not wcs_cfg.get('postgresql'):
# this is not a site configured to use SQL
return False
database_name = wcs_cfg['postgresql'].get('database', 'wcs')
domain_table_name = self.domain.replace('-', '_').replace('.', '_')
if '_' in database_name:
database_name = '%s_%s' % (database_name.split('_')[0], domain_table)
else:
database_name = '%s_%s' % (database_name, domain_table)
try:
pgconn = psycopg2.connect(**wcs_cfg['postgresql'])
except psycopg2.Error:
# XXX: log
raise
cur = pgconn.cursor()
cur.execute('''CREATE DATABASE %s''' % database_name)
pgconn.commit()
cur.close()
wcs_cfg['postgresql']['database'] = database_name
return True
def make_sql_tables(self, wcs_cfg):
params = []
for param in ('dbname', 'user', 'password', 'host', 'port'):
if wcs_cfg.get('postgresql').get(param):
params.append(param)
params.append(wcs_cfg.get('postgresql').get(param))
os.system('wcsctl convertsql %s %s' % (' '.join(params), self.domain))
def make_sso_config(self, wcs_cfg): def make_sso_config(self, wcs_cfg):
has_idff = False has_idff = False
has_saml2 = False has_saml2 = False