Expand source code
Browse git
def setStrategy(searchExe, strategy, keep=False):
error = searchExe.api.TF.error
_msgCache = searchExe._msgCache
if strategy is None:
if keep:
return
strategy = STRATEGY[0]
if strategy not in STRATEGY:
error(f'Strategy not defined: "{strategy}"', cache=_msgCache)
error(
"Allowed strategies:\n{}".format("\n".join(f" {s}" for s in STRATEGY)),
tm=False,
cache=_msgCache,
)
searchExe.good = False
func = globals().get(f"_{strategy}", None)
if not func:
error(f'Strategy is defined, but not implemented: "{strategy}"', cache=_msgCache)
searchExe.good = False
searchExe.strategy = types.MethodType(func, searchExe)
searchExe.strategyName = strategy