Skip to content
Snippets Groups Projects
Commit 01449bfb authored by Vo Minh Thu's avatar Vo Minh Thu
Browse files

[IMP] post_load: factored common code. This also fix bug lp:929466

lp bug: https://launchpad.net/bugs/929466 fixed

bzr revid: vmt@openerp.com-20120209152732-24ud1f70krliv2k5
parent d14a3e9d
No related branches found
No related tags found
No related merge requests found
......@@ -241,10 +241,7 @@ if __name__ == "__main__":
for m in openerp.conf.server_wide_modules:
try:
if m not in openerp.modules.module.loaded:
__import__('openerp.addons.' + m)
openerp.modules.module.loaded.append(m)
openerp.modules.module.call_post_load_hook(m)
openerp.modules.module.load_openerp_module(m)
except Exception:
msg = ''
if m == 'web':
......
......@@ -36,7 +36,7 @@ from openerp.modules.module import \
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
......
......@@ -56,10 +56,9 @@ from openerp.tools.translate import _
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__)
......@@ -163,7 +162,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
_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)
......
......@@ -389,53 +389,43 @@ def init_module_models(cr, module_name, obj_list):
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
......
......@@ -464,10 +464,7 @@ def on_starting(server):
openerp.modules.loading.open_openerp_namespace()
for m in openerp.conf.server_wide_modules:
try:
if m not in openerp.modules.module.loaded:
__import__('openerp.addons.' + m)
openerp.modules.module.call_post_load_hook(m)
openerp.modules.module.loaded.append(m)
openerp.modules.module.load_openerp_module(m)
except Exception:
msg = ''
if m == 'web':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment