diff --git a/openerp/cli/scaffold.py b/openerp/cli/scaffold.py index 700ffbbd212..7268bbc9cb7 100644 --- a/openerp/cli/scaffold.py +++ b/openerp/cli/scaffold.py @@ -11,6 +11,7 @@ import sys import jinja2 from . import Command +from openerp.modules.module import get_module_root MANIFEST = '__openerp__' @@ -181,22 +182,6 @@ def directory(p, create=False): die("%s exists but is not a directory" % p) return expanded -def get_module_root(path): - """ - Get closest module's root begining from path - - @param path: Path from which the lookup should start - - @return: Module root path - """ - # find the module's root directory - while not os.path.exists(os.path.join(path, '%s.py' % MANIFEST)): - new_path = os.path.abspath(os.path.join(path, os.pardir)) - if path == new_path: - return None - path = new_path - return path - def die(message, code=1): print >>sys.stderr, message sys.exit(code) diff --git a/openerp/modules/module.py b/openerp/modules/module.py index 0ccb2865796..0691c98768b 100644 --- a/openerp/modules/module.py +++ b/openerp/modules/module.py @@ -37,6 +37,8 @@ import openerp.tools as tools import openerp.release as release from openerp.tools.safe_eval import safe_eval as eval +MANIFEST = '__openerp__.py' + _logger = logging.getLogger(__name__) # addons path as a list @@ -169,6 +171,33 @@ def get_module_icon(module): return ('/' + module + '/') + '/'.join(iconpath) return '/base/' + '/'.join(iconpath) +def get_module_root(path): + """ + Get closest module's root begining from path + + # Given: + # /foo/bar/module_dir/static/src/... + + get_module_root('/foo/bar/module_dir/static/') + # returns '/foo/bar/module_dir' + + get_module_root('/foo/bar/module_dir/') + # returns '/foo/bar/module_dir' + + get_module_root('/foo/bar') + # returns None + + @param path: Path from which the lookup should start + + @return: Module root path or None if not found + """ + while not os.path.exists(os.path.join(path, MANIFEST)): + new_path = os.path.abspath(os.path.join(path, os.pardir)) + if path == new_path: + return None + path = new_path + return path + def load_information_from_description_file(module, mod_path=None): """ :param module: The name of the module (sale, purchase, ...) @@ -177,7 +206,7 @@ def load_information_from_description_file(module, mod_path=None): if not mod_path: mod_path = get_module_path(module) - terp_file = mod_path and opj(mod_path, '__openerp__.py') or False + terp_file = mod_path and opj(mod_path, MANIFEST) or False if terp_file: info = {} if os.path.isfile(terp_file): @@ -219,7 +248,7 @@ def load_information_from_description_file(module, mod_path=None): #TODO: refactor the logger in this file to follow the logging guidelines # for 6.0 - _logger.debug('module %s: no __openerp__.py file found.', module) + _logger.debug('module %s: no %s file found.', module, MANIFEST) return {} def init_module_models(cr, module_name, obj_list): @@ -291,7 +320,7 @@ def get_modules(): return name def is_really_module(name): - manifest_name = opj(dir, name, '__openerp__.py') + manifest_name = opj(dir, name, MANIFEST) zipfile_name = opj(dir, name) return os.path.isfile(manifest_name) return map(clean, filter(is_really_module, os.listdir(dir)))