2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-09-06 15:29:27 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 07:24:04 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-09-06 15:29:27 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
##############################################################################
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
pool_dic = {}
|
|
|
|
|
2010-07-04 13:49:37 +00:00
|
|
|
def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False, pooljobs=True):
|
2008-07-22 14:24:36 +00:00
|
|
|
if not status:
|
|
|
|
status={}
|
2010-03-11 05:51:33 +00:00
|
|
|
|
2008-12-08 14:03:42 +00:00
|
|
|
db = get_db_only(db_name)
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2008-07-22 14:24:36 +00:00
|
|
|
if db_name in pool_dic:
|
|
|
|
pool = pool_dic[db_name]
|
|
|
|
else:
|
2008-12-08 14:03:42 +00:00
|
|
|
import addons
|
|
|
|
import osv.osv
|
2008-07-22 14:24:36 +00:00
|
|
|
pool = osv.osv.osv_pool()
|
|
|
|
pool_dic[db_name] = pool
|
2010-09-06 15:29:27 +00:00
|
|
|
|
2009-01-07 14:52:34 +00:00
|
|
|
try:
|
|
|
|
addons.load_modules(db, force_demo, status, update_module)
|
2010-09-06 15:29:27 +00:00
|
|
|
except Exception:
|
2009-01-07 14:52:34 +00:00
|
|
|
del pool_dic[db_name]
|
|
|
|
raise
|
|
|
|
|
2008-08-17 18:28:29 +00:00
|
|
|
cr = db.cursor()
|
2008-12-16 10:24:03 +00:00
|
|
|
try:
|
|
|
|
pool.init_set(cr, False)
|
2010-10-01 11:25:52 +00:00
|
|
|
pool.get('ir.actions.report.xml').register_all(cr)
|
2008-12-16 10:24:03 +00:00
|
|
|
cr.commit()
|
|
|
|
finally:
|
|
|
|
cr.close()
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-07-04 13:49:37 +00:00
|
|
|
if pooljobs:
|
2010-09-06 15:29:27 +00:00
|
|
|
pool.get('ir.cron').restart(db.dbname)
|
2008-07-22 14:24:36 +00:00
|
|
|
return db, pool
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2008-12-24 00:24:18 +00:00
|
|
|
def restart_pool(db_name, force_demo=False, status=None, update_module=False):
|
|
|
|
if db_name in pool_dic:
|
|
|
|
del pool_dic[db_name]
|
|
|
|
return get_db_and_pool(db_name, force_demo, status, update_module=update_module)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
def get_db_only(db_name):
|
2008-12-08 14:03:42 +00:00
|
|
|
# ATTENTION:
|
|
|
|
# do not put this import outside this function
|
|
|
|
# sql_db must not be loaded before the logger is initialized.
|
|
|
|
# sql_db import psycopg2.tool which create a default logger if there is not.
|
|
|
|
# this resulting of having the logs outputed twice...
|
|
|
|
import sql_db
|
|
|
|
db = sql_db.db_connect(db_name)
|
2008-07-22 14:24:36 +00:00
|
|
|
return db
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
def get_db(db_name):
|
2008-07-22 14:24:36 +00:00
|
|
|
return get_db_and_pool(db_name)[0]
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-08-12 14:44:56 +00:00
|
|
|
|
2007-07-23 05:16:03 +00:00
|
|
|
def get_pool(db_name, force_demo=False, status=None, update_module=False):
|
2008-07-22 14:24:36 +00:00
|
|
|
pool = get_db_and_pool(db_name, force_demo, status, update_module)[1]
|
|
|
|
return pool
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|