load_information_from_description_file, \
get_module_resource, zip_directory, \
get_module_path, initialize_sys_path, \
- register_module_classes, init_module_models
+ load_openerp_module, init_module_models
from openerp.modules.loading import load_modules
from openerp.modules.module import \
get_modules, get_modules_with_version, \
load_information_from_description_file, \
- call_post_load_hook, \
get_module_resource, zip_directory, \
get_module_path, initialize_sys_path, \
- register_module_classes, init_module_models
+ load_openerp_module, init_module_models
_logger = logging.getLogger(__name__)
_logger.info('module %s: loading objects', package.name)
migrations.migrate_module(package, 'pre')
- register_module_classes(package.name)
+ load_openerp_module(package.name)
models = pool.load(cr, package)
loaded_modules.append(package.name)
t[1](cr, *t[2])
cr.commit()
-def register_module_classes(m):
- """ Register module named m, if not already registered.
+def load_openerp_module(module_name):
+ """ Load an OpenERP module, if not already loaded.
This loads the module and register all of its models, thanks to either
the MetaModel metaclass, or the explicit instantiation of the model.
-
+ This is also used to load server-wide module (i.e. it is also used
+ when there is no model to register).
"""
-
- def log(e):
- mt = isinstance(e, zipimport.ZipImportError) and 'zip ' or ''
- msg = "Couldn't load %smodule %s" % (mt, m)
- _logger.critical(msg)
- _logger.critical(e)
-
global loaded
- if m in loaded:
+ if module_name in loaded:
return
initialize_sys_path()
try:
- mod_path = get_module_path(m)
+ mod_path = get_module_path(module_name)
zip_mod_path = mod_path + '.zip'
if not os.path.isfile(zip_mod_path):
- __import__('openerp.addons.' + m)
+ __import__('openerp.addons.' + module_name)
else:
zimp = zipimport.zipimporter(zip_mod_path)
- zimp.load_module(m)
+ zimp.load_module(module_name)
+
+ # Call the module's post-load hook. This can done before any model or
+ # data has been initialized. This is ok as the post-load hook is for
+ # server-wide (instead of registry-specific) functionalities.
+ info = load_information_from_description_file(module_name)
+ if info['post_load']:
+ getattr(sys.modules['openerp.addons.' + module_name], info['post_load'])()
+
except Exception, e:
- log(e)
+ mt = isinstance(e, zipimport.ZipImportError) and 'zip ' or ''
+ msg = "Couldn't load %smodule %s" % (mt, module_name)
+ _logger.critical(msg)
+ _logger.critical(e)
raise
else:
- loaded.append(m)
-
- call_post_load_hook(m)
-
-# TODO replace the __import__() by register_module_classes() above
-# and combine call_post_load_hook with it for 6.2.
-def call_post_load_hook(module_name):
- """
- Call the module's post-load hook. This can done before any model or
- data has been initialized. This is ok as the post-load hook is for
- server-wide (instead of registry-specific) functionalities.
- The module must have been loaded with as openerp.addons.<module_name>.
- """
- info = load_information_from_description_file(module_name)
- if info['post_load']:
- getattr(sys.modules['openerp.addons.' + module_name], info['post_load'])()
+ loaded.append(module_name)
def get_modules():
"""Returns the list of module names