diff options
| author | Vo Minh Thu <vmt@openerp.com> | 2011-02-08 10:29:23 +0100 |
|---|---|---|
| committer | Vo Minh Thu <vmt@openerp.com> | 2011-02-08 10:29:23 +0100 |
| commit | 45239ae4935050ae76b1ddfcbe3b5362e2cc04e4 (patch) | |
| tree | d39b8688aeb118fa715b8002d0002e14a1cc8b87 | |
| parent | ec17bb9e74548a78da9a75ab4475e153d7f624b6 (diff) | |
[IMP] openerp.__init__ can imports all its submodules.
- The config parser is given sys.args explicitely
- addons.__init__ changed so it can be imported in openerp.__init__
bzr revid: vmt@openerp.com-20110208092923-42mj8sb8mkfbiytw
| -rwxr-xr-x | openerp-server.py | 2 | ||||
| -rw-r--r-- | openerp/__init__.py | 15 | ||||
| -rw-r--r-- | openerp/addons/__init__.py | 32 | ||||
| -rw-r--r-- | openerp/tools/config.py | 6 |
4 files changed, 31 insertions, 24 deletions
diff --git a/openerp-server.py b/openerp-server.py index bf4dc781b55..1486c493ff5 100755 --- a/openerp-server.py +++ b/openerp-server.py @@ -56,7 +56,7 @@ if os.name == 'posix': # import the tools module so that the commandline parameters are parsed #----------------------------------------------------------------------- import openerp.tools as tools -tools.config.parse_config() +tools.config.parse_config(sys.argv[1:]) #---------------------------------------------------------- # get logger diff --git a/openerp/__init__.py b/openerp/__init__.py index 43230ef2dfa..c5f7732edd0 100644 --- a/openerp/__init__.py +++ b/openerp/__init__.py @@ -19,26 +19,21 @@ # ############################################################################## -# We don't want addons to be imported right now; -# the commented imports import addons. -# This will change when addons.__init__ and addons.base -# are cleaned. - -#import addons +import addons import ir import loglevels import netsvc import osv -#import pooler +import pooler import pychart import release -#import report +import report import run_tests -#import service +import service import sql_db import test import tiny_socket -#import tools +import tools import wizard import workflow diff --git a/openerp/addons/__init__.py b/openerp/addons/__init__.py index fa71f7ffbee..83f8db8acd2 100644 --- a/openerp/addons/__init__.py +++ b/openerp/addons/__init__.py @@ -46,21 +46,29 @@ import logging logger = netsvc.Logger() -_ad = os.path.abspath(opj(tools.ustr(tools.config['root_path']), u'addons')) # default addons path (base) -ad_paths= map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(',')) +_ad = os.path.dirname(__file__) # default addons path (base) +ad_paths = [] -sys.path.insert(1, _ad) +# Modules already loaded +loaded = [] -ad_cnt=1 -for adp in ad_paths: - if adp != _ad: - sys.path.insert(ad_cnt, adp) - ad_cnt+=1 +def initialize_sys_path(): + global ad_paths -ad_paths.append(_ad) # for get_module_path + if ad_paths: + return -# Modules already loaded -loaded = [] + ad_paths = map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(',')) + + sys.path.insert(1, _ad) + + ad_cnt=1 + for adp in ad_paths: + if adp != _ad: + sys.path.insert(ad_cnt, adp) + ad_cnt+=1 + + ad_paths.append(_ad) # for get_module_path class Graph(dict): @@ -798,6 +806,8 @@ def _check_module_names(cr, module_names): 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: diff --git a/openerp/tools/config.py b/openerp/tools/config.py index 3a3fb4575cd..c7e99e28737 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -233,8 +233,10 @@ class configmanager(object): security.add_option('--no-database-list', action="store_false", dest='list_db', help="disable the ability to return the list of databases") parser.add_option_group(security) - def parse_config(self): - opt = self.parser.parse_args()[0] + self.parse_config() + + def parse_config(self, args=[]): + opt = self.parser.parse_args(args)[0] def die(cond, msg): if cond: |
