From 8d826cc07d8b8751229e7493a73f3e9bb61ae0a3 Mon Sep 17 00:00:00 2001 From: "nicolas.bessi@camptocamp.com" <> Date: Tue, 17 Jan 2012 17:49:40 +0100 Subject: [PATCH] [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 --- gunicorn.conf.py | 6 +++--- openerp/service/web_services.py | 10 ++++++---- openerp/sql_db.py | 4 +++- openerp/tools/config.py | 5 ++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 9962493d549..949ccc0b68d 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -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, diff --git a/openerp/service/web_services.py b/openerp/service/web_services.py index f486a050a7f..01d45611d60 100644 --- a/openerp/service/web_services.py +++ b/openerp/service/web_services.py @@ -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 = [] diff --git a/openerp/sql_db.py b/openerp/sql_db.py index 63ab2a13fb9..f3a043d7a54 100644 --- a/openerp/sql_db.py +++ b/openerp/sql_db.py @@ -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 diff --git a/openerp/tools/config.py b/openerp/tools/config.py index 00815ed2055..1d346921a7d 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -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',