[MERGE] added --db-template option.
bzr revid: vmt@openerp.com-20120118145334-sa190ihcos9iflcu
This commit is contained in:
@@ -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 = []
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
@@ -217,6 +217,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 +348,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',
|
||||
|
||||
Reference in New Issue
Block a user