summaryrefslogtreecommitdiff
path: root/openerp/modules/__init__.py
diff options
context:
space:
mode:
authorVo Minh Thu <vmt@openerp.com>2011-04-28 17:13:30 +0200
committerVo Minh Thu <vmt@openerp.com>2011-04-28 17:13:30 +0200
commit081b6d98abd93e0d09d3fbf2cc8e3aec7db8f47f (patch)
tree58df466bcb4728c8ca8c48955aeabfef04f75b9b /openerp/modules/__init__.py
parent041a61c1b11f724eb4d548f3539b239b9e43c02a (diff)
[REF] separate/expose some code.
bzr revid: vmt@openerp.com-20110428151330-m8qkggoqmsry3w2z
Diffstat (limited to 'openerp/modules/__init__.py')
-rw-r--r--openerp/modules/__init__.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/openerp/modules/__init__.py b/openerp/modules/__init__.py
index 2c5c3e037fc..d4205ad9976 100644
--- a/openerp/modules/__init__.py
+++ b/openerp/modules/__init__.py
@@ -29,6 +29,8 @@ from os.path import join as opj
import itertools
import zipimport
+import openerp
+
import openerp.osv as osv
import openerp.tools as tools
import openerp.tools.osutil as osutil
@@ -74,6 +76,13 @@ def initialize_sys_path():
ad_paths.append(_ad) # for get_module_path
+def open_openerp_namespace():
+ # See comment for open_openerp_namespace.
+ if openerp.conf.deprecation.open_openerp_namespace:
+ for k, v in list(sys.modules.items()):
+ if k.startswith('openerp.') and sys.modules.get(k[8:]) is None:
+ sys.modules[k[8:]] = v
+
class Graph(dict):
""" Modules dependency graph.
@@ -457,6 +466,16 @@ def init_module_objects(cr, module_name, obj_list):
cr.commit()
+def load_module(module_name):
+ """ Load a Python module found on the addons paths."""
+ fm = imp.find_module(module_name, ad_paths)
+ try:
+ imp.load_module(module_name, *fm)
+ finally:
+ if fm[0]:
+ fm[0].close()
+
+
def register_class(m):
"""
Register module named m, if not already registered
@@ -478,12 +497,7 @@ def register_class(m):
try:
zip_mod_path = mod_path + '.zip'
if not os.path.isfile(zip_mod_path):
- fm = imp.find_module(m, ad_paths)
- try:
- imp.load_module(m, *fm)
- finally:
- if fm[0]:
- fm[0].close()
+ load_module(m)
else:
zimp = zipimport.zipimporter(zip_mod_path)
zimp.load_module(m)
@@ -834,10 +848,7 @@ def load_modules(db, force_demo=False, status=None, update_module=False):
initialize_sys_path()
- # Backward compatibility: addons don't have to import openerp.xxx, they still can import xxx
- for k, v in list(sys.modules.items()):
- if k.startswith('openerp.') and sys.modules.get(k[8:]) is None:
- sys.modules[k[8:]] = v
+ open_openerp_namespace()
if not status:
status = {}