From f4698375636d5d73e1e8687e6d387fec20bc9b2c Mon Sep 17 00:00:00 2001 From: Amit Mendapara Date: Tue, 15 Jul 2008 13:40:40 +0530 Subject: [PATCH] Custom addons path now overrides default addons path. - `root_path`/addons is default - `addons_path` overrides default path (will get precedence over default path) - added `--addons-path` command line option bzr revid: ame@tinyerp.com-20080715081040-fqmfvx7jxl6d5hn3 --- bin/addons/__init__.py | 25 +++++++++++++++++++------ bin/tools/config.py | 9 +++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index d4dff56bfae..1d70eb80012 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -44,8 +44,13 @@ import zipfile logger = netsvc.Logger() opj = os.path.join -ad = tools.config['addons_path'] -sys.path.insert(1,ad) + +_ad = opj(tools.config['root_path'], 'addons') # default addons path (base) +ad = tools.config['addons_path'] # alternate addons path + +sys.path.insert(1, _ad) +if ad != _ad: + sys.path.insert(1, ad) class Graph(dict): @@ -126,6 +131,11 @@ class Node(Singleton): s += '%s`-> %s' % (' ' * depth, c._pprint(depth+1)) return s +def _get_module_path(module): + if os.path.exists(opj(ad, module)): + return opj(ad, module) + return opj(_ad, module) + def create_graph(module_list, force=None): if not force: force=[] @@ -135,8 +145,8 @@ def create_graph(module_list, force=None): for module in module_list: if module[-4:]=='.zip': module = module[:-4] - terp_file = opj(ad, module, '__terp__.py') - mod_path = opj(ad, module) + mod_path = _get_module_path(module) + terp_file = opj(mod_path, '__terp__.py') if os.path.isfile(terp_file) or zipfile.is_zipfile(mod_path+'.zip'): try: info = eval(tools.file_open(terp_file).read()) @@ -245,17 +255,20 @@ def load_module_graph(cr, graph, status=None, **kwargs): def register_classes(): module_list = os.listdir(ad) + module_list += [m for m in os.listdir(_ad) if m not in module_list] + for package in create_graph(module_list): m = package.name logger.notifyChannel('init', netsvc.LOG_INFO, 'addon:%s:registering classes' % m) sys.stdout.flush() - if not os.path.isfile(opj(ad, m+'.zip')): + mod_path = _get_module_path(m) + if not os.path.isfile(mod_path + '.zip'): # XXX must restrict to only addons paths imp.load_module(m, *imp.find_module(m)) else: import zipimport - mod_path = opj(ad, m+'.zip') + mod_path = mod_path + '.zip' try: zimp = zipimport.zipimporter(mod_path) zimp.load_module(m) diff --git a/bin/tools/config.py b/bin/tools/config.py index 4098029ca6d..1948d725b36 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -121,6 +121,7 @@ class configmanager(object): group.add_option("--i18n-export", dest="translate_out", help="export all sentences to be translated to a CSV file and exit") group.add_option("--i18n-import", dest="translate_in", help="import a CSV file with translations and exit") group.add_option("--modules", dest="translate_modules", help="specify modules to export. Use in combination with --i18n-export") + group.add_option("--addons-path", dest="addons_path", help="specify an alternative addons path.") parser.add_option_group(group) (opt, args) = parser.parse_args() @@ -142,13 +143,13 @@ class configmanager(object): # Verify that we want to log or not, if not the output will go to stdout if self.options['logfile'] in ('None', 'False'): - self.options['logfile'] = False + self.options['logfile'] = False # the same for the pidfile - if self.options['pidfile'] in ('None', 'False'): - self.options['pidfile'] = False + if self.options['pidfile'] in ('None', 'False'): + self.options['pidfile'] = False for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host', - 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode'): + 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode', 'addons_path'): if getattr(opt, arg): self.options[arg] = getattr(opt, arg)