report total
[odoo/odoo.git] / bin / pooler.py
1 ##############################################################################
2 #
3 # Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsability of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # garantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 #
26 ##############################################################################
27
28 import sql_db
29 import osv.osv
30 import tools
31 import addons
32 import netsvc
33
34 db_dic = {}
35 pool_dic = {}
36
37 def get_db_and_pool(db_name, force_demo=False, status={}, update_module=False):
38         if db_name in db_dic:
39                 db = db_dic[db_name]
40         else:
41                 logger = netsvc.Logger()
42                 logger.notifyChannel('pooler', netsvc.LOG_INFO, 'Connecting to %s' % (db_name))
43                 db = sql_db.db_connect(db_name)
44                 db_dic[db_name] = db
45         
46         if db_name in pool_dic:
47                 pool = pool_dic[db_name]
48         else:
49                 pool = osv.osv.osv_pool()
50                 pool_dic[db_name] = pool
51                 addons.load_modules(db, force_demo, status, update_module)
52
53                 import report
54                 report.interface.register_all(db)
55
56                 pool.get('ir.cron')._poolJobs(db.dbname)
57         return db, pool
58
59 def restart_pool(db_name, force_demo=False, update_module=False):
60 #       del db_dic[db_name]
61         del pool_dic[db_name]
62         return get_db_and_pool(db_name, force_demo, update_module=update_module)
63
64 def close_db(db_name):
65         if db_name in db_dic:
66                 db_dic[db_name].truedb.close()
67                 del db_dic[db_name]
68         if db_name in pool_dic:
69                 del pool_dic[db_name]
70
71 def get_db_only(db_name):
72         if db_name in db_dic:
73                 db = db_dic[db_name]
74         else:
75                 db = sql_db.db_connect(db_name)
76                 db_dic[db_name] = db
77         return db
78
79 def get_db(db_name):
80 #       print "get_db", db_name
81         return get_db_and_pool(db_name)[0]
82
83 def get_pool(db_name, force_demo=False, status={}, update_module=False):
84 #       print "get_pool", db_name
85         pool = get_db_and_pool(db_name, force_demo, status, update_module)[1]
86 #       addons.load_modules(db_name, False)
87 #       if not pool.obj_list():
88 #               pool.instanciate()
89 #       print "pool", pool
90         return pool
91 #       return get_db_and_pool(db_name)[1]
92
93 def init():
94         global db
95 #       db = get_db_only(tools.config['db_name'])
96         sql_db.init()
97