[IMP] database template in commande line, you can now use --db_template=my_template, default is template0

bzr revid: nicolas.bessi@camptocamp.com-20120117164940-i3g1zcu49x0g60t5
This commit is contained in:
nicolas.bessi@camptocamp.com 2012-01-17 17:49:40 +01:00
parent 76cb307537
commit 8d826cc07d
4 changed files with 16 additions and 9 deletions

View File

@ -35,14 +35,14 @@ conf = openerp.tools.config
# Path to the OpenERP Addons repository (comma-separated for
# multiple locations)
conf['addons_path'] = '/home/openerp/addons/trunk,/home/openerp/web/trunk/addons'
conf['addons_path'] = '/opt/openerp_61Launchpad/src/webclient/addons/,/opt/openerp_61Launchpad/src/server/openerp/addons'
# Optional database config if not using local socket
#conf['db_name'] = 'mycompany'
#conf['db_host'] = 'localhost'
#conf['db_user'] = 'foo'
conf['db_user'] = 'openerp_geoengine'
#conf['db_port'] = 5432
#conf['db_password'] = 'secret'
conf['db_password'] = 'toto'
# OpenERP Log Level
# DEBUG=10, DEBUG_RPC=8, DEBUG_RPC_ANSWER=6, DEBUG_SQL=5, INFO=20,

View File

@ -116,9 +116,10 @@ class db(netsvc.ExportService):
def _create_empty_database(self, name):
db = sql_db.db_connect('template1')
cr = db.cursor()
chosen_template = tools.config['db_template']
try:
cr.autocommit(True) # avoid transaction block
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "template0" """ % name)
cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (name, chosen_template))
finally:
cr.close()
@ -304,7 +305,8 @@ class db(netsvc.ExportService):
def exp_list(self, document=False):
if not tools.config['list_db'] and not document:
raise openerp.exceptions.AccessDenied()
chosen_template = tools.config['db_template']
templates_list = tuple(set(['template0', 'template1', 'postgres', chosen_template]))
db = sql_db.db_connect('template1')
cr = db.cursor()
try:
@ -318,9 +320,9 @@ class db(netsvc.ExportService):
res = cr.fetchone()
db_user = res and str(res[0])
if db_user:
cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in ('template0', 'template1', 'postgres') order by datname", (db_user,))
cr.execute("select decode(datname, 'escape') from pg_database where datdba=(select usesysid from pg_user where usename=%s) and datname not in %s order by datname", (db_user, templates_list))
else:
cr.execute("select decode(datname, 'escape') from pg_database where datname not in('template0', 'template1','postgres') order by datname")
cr.execute("select decode(datname, 'escape') from pg_database where datname not in %s order by datname", (templates_list,))
res = [str(name) for (name,) in cr.fetchall()]
except Exception:
res = []

View File

@ -302,7 +302,9 @@ class Cursor(object):
if leak:
self._cnx.leaked = True
else:
keep_in_pool = self.dbname not in ('template1', 'template0', 'postgres')
chosen_template = tools.config['db_template']
templates_list = tuple(set(['template0', 'template1', 'postgres', chosen_template]))
keep_in_pool = self.dbname not in templates_list
self._pool.give_back(self._cnx, keep_in_pool=keep_in_pool)
@check

View File

@ -68,6 +68,7 @@ class configmanager(object):
'publisher_warranty_url': 'http://services.openerp.com/publisher-warranty/',
'reportgz': False,
'root_path': None,
'db_template': 'template0',
}
# Not exposed in the configuration file.
@ -217,6 +218,8 @@ class configmanager(object):
help="specify the database port", type="int")
group.add_option("--db_maxconn", dest="db_maxconn", type='int', my_default=64,
help="specify the the maximum number of physical connections to posgresql")
group.add_option("--db_template", dest="db_template", my_default='template0',
help="specify a custom database template to create a new database")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Internationalisation options",
@ -346,7 +349,7 @@ class configmanager(object):
self.options['pidfile'] = False
keys = ['xmlrpc_interface', 'xmlrpc_port', 'db_name', 'db_user', 'db_password', 'db_host',
'db_port', 'logfile', 'pidfile', 'smtp_port', 'cache_timeout',
'db_port', 'db_template', 'logfile', 'pidfile', 'smtp_port', 'cache_timeout',
'email_from', 'smtp_server', 'smtp_user', 'smtp_password',
'netrpc_interface', 'netrpc_port', 'db_maxconn', 'import_partial', 'addons_path',
'netrpc', 'xmlrpc', 'syslog', 'without_demo', 'timezone',