[IMP] loading: call post-load hook in non-server-wide-module too.
bzr revid: vmt@openerp.com-20120209141444-12261k6zd2ovnltd
This commit is contained in:
parent
1f189228b5
commit
d14a3e9df0
|
@ -241,11 +241,10 @@ if __name__ == "__main__":
|
|||
|
||||
for m in openerp.conf.server_wide_modules:
|
||||
try:
|
||||
__import__('openerp.addons.' + m)
|
||||
# Call any post_load hook.
|
||||
info = openerp.modules.module.load_information_from_description_file(m)
|
||||
if info['post_load']:
|
||||
getattr(sys.modules[m], info['post_load'])()
|
||||
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)
|
||||
except Exception:
|
||||
msg = ''
|
||||
if m == 'web':
|
||||
|
|
|
@ -56,6 +56,7 @@ 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
|
||||
|
@ -163,6 +164,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)
|
||||
|
||||
models = pool.load(cr, package)
|
||||
loaded_modules.append(package.name)
|
||||
if hasattr(package, 'init') or hasattr(package, 'update') or package.state in ('to install', 'to upgrade'):
|
||||
|
|
|
@ -406,11 +406,10 @@ def register_module_classes(m):
|
|||
global loaded
|
||||
if m in loaded:
|
||||
return
|
||||
_logger.info('module %s: registering objects', m)
|
||||
mod_path = get_module_path(m)
|
||||
|
||||
initialize_sys_path()
|
||||
try:
|
||||
mod_path = get_module_path(m)
|
||||
zip_mod_path = mod_path + '.zip'
|
||||
if not os.path.isfile(zip_mod_path):
|
||||
__import__('openerp.addons.' + m)
|
||||
|
@ -423,6 +422,20 @@ def register_module_classes(m):
|
|||
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'])()
|
||||
|
||||
def get_modules():
|
||||
"""Returns the list of module names
|
||||
|
|
|
@ -464,11 +464,10 @@ def on_starting(server):
|
|||
openerp.modules.loading.open_openerp_namespace()
|
||||
for m in openerp.conf.server_wide_modules:
|
||||
try:
|
||||
__import__(m)
|
||||
# Call any post_load hook.
|
||||
info = openerp.modules.module.load_information_from_description_file(m)
|
||||
if info['post_load']:
|
||||
getattr(sys.modules[m], info['post_load'])()
|
||||
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)
|
||||
except Exception:
|
||||
msg = ''
|
||||
if m == 'web':
|
||||
|
|
Loading…
Reference in New Issue