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