[IMP] translations: simplify condition in qweb terms extraction
[odoo/odoo.git] / openerp / pooler.py
index b162bba..5ada4c2 100644 (file)
 #
 ##############################################################################
 
-import sql_db
+""" Functions kept for backward compatibility.
 
-pool_dic = {}
+    They are simple wrappers around a global RegistryManager methods.
 
-def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False, pooljobs=True):
-    """Return a database connection and an initialized osv_pool."""
-    if not status:
-        status={}
+"""
 
-    db = sql_db.db_connect(db_name)
+import logging
+import openerp.conf.deprecation
+from openerp.modules.registry import RegistryManager
 
-    if db_name in pool_dic:
-        pool = pool_dic[db_name]
-    else:
-        import openerp.modules
-        import openerp.osv.osv as osv_osv
-        pool = osv_osv.osv_pool()
+_logger = logging.getLogger(__name__)
 
-        # Initializing an osv_pool will call general code which will in turn
-        # call get_db_and_pool (this function) to obtain the osv_pool begin
-        # initialized. Make it available in the pool_dic then remove it if
-        # an exception is raised.
-        pool_dic[db_name] = pool
-        try:
-            openerp.modules.load_modules(db, force_demo, status, update_module)
-        except Exception:
-            del pool_dic[db_name]
-            raise
-
-        cr = db.cursor()
-        try:
-            pool.init_set(cr, False)
-            pool.get('ir.actions.report.xml').register_all(cr)
-            cr.commit()
-        finally:
-            cr.close()
-
-        if pooljobs:
-            pool.get('ir.cron').restart(db.dbname)
-    return db, pool
+def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
+    """Create and return a database connection and a newly initialized registry."""
+    assert openerp.conf.deprecation.openerp_pooler
+    _logger.warning('openerp.pooler.get_db_and_pool() is deprecated.')
+    registry = RegistryManager.get(db_name, force_demo, status, update_module)
+    return registry._db, registry
 
 
 def restart_pool(db_name, force_demo=False, status=None, update_module=False):
-    """Delete an existing osv_pool and return a database connection and a newly initialized osv_pool."""
-    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)
-
+    """Delete an existing registry and return a database connection and a newly initialized registry."""
+    _logger.warning('openerp.pooler.restart_pool() is deprecated.')
+    assert openerp.conf.deprecation.openerp_pooler
+    registry = RegistryManager.new(db_name, force_demo, status, update_module)
+    return registry._db, registry
 
 def get_db(db_name):
-    """Return a database connection. The corresponding osv_pool is initialize."""
+    """Return a database connection. The corresponding registry is initialized."""
+    assert openerp.conf.deprecation.openerp_pooler
     return get_db_and_pool(db_name)[0]
 
 
 def get_pool(db_name, force_demo=False, status=None, update_module=False):
-    """Return an osv_pool."""
-    pool = get_db_and_pool(db_name, force_demo, status, update_module)[1]
-    return pool
+    """Return a model registry."""
+    assert openerp.conf.deprecation.openerp_pooler
+    return get_db_and_pool(db_name, force_demo, status, update_module)[1]
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: