diff --git a/openerp/addons/base/module/wizard/base_module_import.py b/openerp/addons/base/module/wizard/base_module_import.py index 6d6f0e1ef8d..2ba789f3332 100644 --- a/openerp/addons/base/module/wizard/base_module_import.py +++ b/openerp/addons/base/module/wizard/base_module_import.py @@ -28,8 +28,6 @@ from openerp import tools from openerp.osv import osv, fields from openerp.tools.translate import _ -ADDONS_PATH = tools.config['addons_path'].split(",")[-1] - class base_module_import(osv.osv_memory): """ Import Module """ diff --git a/openerp/cli/server.py b/openerp/cli/server.py index ee2e90bccbd..7041d7a4c3c 100644 --- a/openerp/cli/server.py +++ b/openerp/cli/server.py @@ -72,7 +72,7 @@ def report_configuration(): """ config = openerp.tools.config _logger.info("OpenERP version %s", __version__) - for name, value in [('addons paths', config['addons_path']), + for name, value in [('addons paths', openerp.modules.module.ad_paths), ('database hostname', config['db_host'] or 'localhost'), ('database port', config['db_port'] or '5432'), ('database user', config['db_user'])]: diff --git a/openerp/modules/module.py b/openerp/modules/module.py index cf3ff61805e..98511234b75 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -3,7 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). -# Copyright (C) 2010-2012 OpenERP s.a. (). +# Copyright (C) 2010-2014 OpenERP s.a. (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -45,7 +45,6 @@ import logging _logger = logging.getLogger(__name__) _test_logger = logging.getLogger('openerp.tests') -_ad = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'addons') # default addons path (base) ad_paths = [] # Modules already loaded @@ -97,8 +96,13 @@ def initialize_sys_path(): if ad_paths: return - ad_paths = map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(',')) - ad_paths.append(os.path.abspath(_ad)) # for get_module_path + ad_paths = [tools.config.addons_data_dir] + ad_paths += map(lambda m: os.path.abspath(tools.ustr(m.strip())), tools.config['addons_path'].split(',')) + + # add base module path + base_path = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'addons')) + ad_paths += [base_path] + sys.meta_path.append(AddonsImportHook()) def get_module_path(module, downloaded=False, display_warning=True): @@ -115,7 +119,7 @@ def get_module_path(module, downloaded=False, display_warning=True): return opj(adp, module) if downloaded: - return opj(_ad, module) + return opj(tools.config.addons_data_dir, module) if display_warning: _logger.warning('module %s: module not found', module) return False diff --git a/openerp/service/server.py b/openerp/service/server.py index 87f10010645..e7fcb610152 100644 --- a/openerp/service/server.py +++ b/openerp/service/server.py @@ -108,15 +108,14 @@ class AutoReload(object): self.handler = EventHandler(self) self.notifier = pyinotify.Notifier(self.wm, self.handler, timeout=0) mask = pyinotify.IN_MODIFY | pyinotify.IN_CREATE # IN_MOVED_FROM, IN_MOVED_TO ? - for path in openerp.tools.config.options["addons_path"].split(','): + for path in openerp.modules.modules.ad_paths: _logger.info('Watching addons folder %s', path) self.wm.add_watch(path, mask, rec=True) def process_data(self, files): xml_files = [i for i in files if i.endswith('.xml')] - addons_path = openerp.tools.config.options["addons_path"].split(',') for i in xml_files: - for path in addons_path: + for path in openerp.modules.modules.ad_paths: if i.startswith(path): # find out wich addons path the file belongs to # and extract it's module name diff --git a/openerp/tests/common.py b/openerp/tests/common.py index df00e61f140..7bd8bf76cc9 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -11,7 +11,6 @@ import xmlrpclib import openerp # The openerp library is supposed already configured. -ADDONS_PATH = openerp.tools.config['addons_path'] PORT = openerp.tools.config['xmlrpc_port'] DB = openerp.tools.config['db_name'] diff --git a/openerp/tools/translate.py b/openerp/tools/translate.py index f82fa4b87ad..72cf4ec1d0b 100644 --- a/openerp/tools/translate.py +++ b/openerp/tools/translate.py @@ -778,49 +778,32 @@ def trans_generate(lang, modules, cr): if model_obj._sql_constraints: push_local_constraints(module, model_obj, 'sql_constraints') - def get_module_from_path(path, mod_paths=None): - if not mod_paths: - # First, construct a list of possible paths - def_path = os.path.abspath(os.path.join(config.config['root_path'], 'addons')) # default addons path (base) - ad_paths= map(lambda m: os.path.abspath(m.strip()),config.config['addons_path'].split(',')) - mod_paths=[def_path] - for adp in ad_paths: - mod_paths.append(adp) - if not os.path.isabs(adp): - mod_paths.append(adp) - elif adp.startswith(def_path): - mod_paths.append(adp[len(def_path)+1:]) - for mp in mod_paths: - if path.startswith(mp) and (os.path.dirname(path) != mp): - path = path[len(mp)+1:] - return path.split(os.path.sep)[0] - return 'base' # files that are not in a module are considered as being in 'base' module modobj = registry['ir.module.module'] installed_modids = modobj.search(cr, uid, [('state', '=', 'installed')]) installed_modules = map(lambda m: m['name'], modobj.read(cr, uid, installed_modids, ['name'])) - root_path = os.path.join(config.config['root_path'], 'addons') - - apaths = map(os.path.abspath, map(str.strip, config.config['addons_path'].split(','))) - if root_path in apaths: - path_list = apaths - else : - path_list = [root_path,] + apaths - + path_list = list(openerp.modules.module.ad_paths) # Also scan these non-addon paths for bin_path in ['osv', 'report' ]: path_list.append(os.path.join(config.config['root_path'], bin_path)) _logger.debug("Scanning modules at paths: ", path_list) - mod_paths = [] + mod_paths = list(path_list) + + def get_module_from_path(path): + for mp in mod_paths: + if path.startswith(mp) and (os.path.dirname(path) != mp): + path = path[len(mp)+1:] + return path.split(os.path.sep)[0] + return 'base' # files that are not in a module are considered as being in 'base' module def verified_module_filepaths(fname, path, root): fabsolutepath = join(root, fname) frelativepath = fabsolutepath[len(path):] display_path = "addons%s" % frelativepath - module = get_module_from_path(fabsolutepath, mod_paths=mod_paths) + module = get_module_from_path(fabsolutepath) if ('all' in modules or module in modules) and module in installed_modules: return module, fabsolutepath, frelativepath, display_path return None, None, None, None