43 from logilab.common.logging_ext import set_log_methods |
43 from logilab.common.logging_ext import set_log_methods |
44 |
44 |
45 from cubicweb import CW_SOFTWARE_ROOT |
45 from cubicweb import CW_SOFTWARE_ROOT |
46 from cubicweb import RegistryNotFound, ObjectNotFound, NoSelectableObject |
46 from cubicweb import RegistryNotFound, ObjectNotFound, NoSelectableObject |
47 from cubicweb.appobject import AppObject, class_regid |
47 from cubicweb.appobject import AppObject, class_regid |
|
48 |
48 |
49 |
49 def _toload_info(path, extrapath, _toload=None): |
50 def _toload_info(path, extrapath, _toload=None): |
50 """return a dictionary of <modname>: <modpath> and an ordered list of |
51 """return a dictionary of <modname>: <modpath> and an ordered list of |
51 (file, module name) to load |
52 (file, module name) to load |
52 """ |
53 """ |
219 if appobjectscore > score: |
220 if appobjectscore > score: |
220 score, winners = appobjectscore, [appobject] |
221 score, winners = appobjectscore, [appobject] |
221 elif appobjectscore > 0 and appobjectscore == score: |
222 elif appobjectscore > 0 and appobjectscore == score: |
222 winners.append(appobject) |
223 winners.append(appobject) |
223 if winners is None: |
224 if winners is None: |
224 raise NoSelectableObject('args: %s\nkwargs: %s %s' |
225 raise NoSelectableObject(args, kwargs, appobjects) |
225 % (args, kwargs.keys(), |
|
226 [repr(v) for v in appobjects])) |
|
227 if len(winners) > 1: |
226 if len(winners) > 1: |
228 # log in production environement / test, error while debugging |
227 # log in production environement / test, error while debugging |
|
228 msg = 'select ambiguity: %s\n(args: %s, kwargs: %s)' |
229 if self.config.debugmode or self.config.mode == 'test': |
229 if self.config.debugmode or self.config.mode == 'test': |
230 raise Exception('select ambiguity, args: %s\nkwargs: %s %s' |
230 # raise bare exception in debug mode |
231 % (args, kwargs.keys(), |
231 raise Exception(msg % (winners, self.args, self.kwargs.keys())) |
232 [repr(v) for v in winners])) |
232 self.error(msg, winners, self.args, self.kwargs.keys()) |
233 self.error('select ambiguity, args: %s\nkwargs: %s %s', |
|
234 args, kwargs.keys(), [repr(v) for v in winners]) |
|
235 # return the result of calling the appobject |
233 # return the result of calling the appobject |
236 return winners[0](*args, **kwargs) |
234 return winners[0](*args, **kwargs) |
237 |
235 |
238 select_best = deprecated('[3.6] select_best is now private')(_select_best) |
236 select_best = deprecated('[3.6] select_best is now private')(_select_best) |
239 |
237 |