""" Models registries.
"""
+from contextlib import contextmanager
import logging
import threading
"""
def __init__(self, db_name):
- self.models = {} # model name/model instance mapping
+ self.models = {} # model name/model instance mapping
self._sql_error = {}
self._store_function = {}
self._init = True
self._init_parent = {}
-
+
# modules fully loaded (maintained during init phase by `loading` module)
self._init_modules = set()
for model in self.models.itervalues():
model.clear_caches()
+ @contextmanager
+ def cursor(self, auto_commit=True):
+ cr = self.db.cursor()
+ try:
+ yield cr
+ if auto_commit:
+ cr.commit()
+ finally:
+ cr.close()
+
+
class RegistryManager(object):
""" Model registries manager.
del cls.registries[db_name]
openerp.cron.cancel(db_name)
-
@classmethod
def delete_all(cls):
"""Delete all the registries. """