[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
This commit is contained in:
Vo Minh Thu 2011-02-08 10:29:23 +01:00
parent ec17bb9e74
commit 45239ae493
4 changed files with 32 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -46,22 +46,30 @@ 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(','))
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
_ad = os.path.dirname(__file__) # default addons path (base)
ad_paths = []
# Modules already loaded
loaded = []
def initialize_sys_path():
global ad_paths
if ad_paths:
return
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):
def addNode(self, name, deps):
@ -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:

View File

@ -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: