196
196
_stack_cache = {}
199
def register_filter_stack_map(name, stack_map, fallback=None):
199
def register_filter_stack_map(name, stack_map_lookup):
200
200
"""Register the filter stacks to use for various preference values.
202
202
:param name: the preference/filter-stack name
203
:param stack_map: a dictionary where
204
the keys are preference values to match and
205
the values are the matching stack of filters for each
206
:param fallback: if non-None, a callable that will be
207
invoked if a preference value is found that doesn't
208
match a key in the stack_map. The callable is expected
209
to take the value as a parameter and either return
210
the matching stack of filters or None if none.
203
:param stack_map_lookup: a callable where
204
the parameter is the preference value to match and
205
the result is the matching stack of filters to use,
212
208
if name in _filter_stacks_registry:
213
209
raise errors.BzrError(
214
210
"filter stack for %s already installed" % name)
215
_filter_stacks_registry.register(name, (stack_map, fallback))
211
_filter_stacks_registry.register(name, stack_map_lookup)
218
214
def lazy_register_filter_stack_map(name, module_name, member_name):
221
217
:param name: the preference/filter-stack name
222
218
:param module_name: The python path to the module of the filter stack map.
223
:param member_name: The name of the (filter stack map, fallback) tuple
219
:param member_name: The name of the stack_map_lookup callable
226
222
if name in _filter_stacks_registry:
253
249
for k, v in preferences:
255
stacks_by_values, fallback = _filter_stacks_registry.get(k)
251
stack_map_lookup = _filter_stacks_registry.get(k)
257
253
# Some preferences may not have associated filters
259
items = stacks_by_values.get(v)
260
if items is None and fallback is not None:
255
items = stack_map_lookup(v)
263
257
stack.extend(items)
264
258
_stack_cache[preferences] = stack