ways.base.finder module¶
The main class/functions used to find actions for Context/Asset objects.
-
class
ways.base.finder.
Find
(context)[source]¶ Bases:
ways.core.compat.DirMixIn
,object
A wrapper around a Context object that provides some basic syntax-sugar.
The syntax of using Context objects is clunky. This class is meant to help. See the second and last example, for details.
Example
>>> context = Context('/some/context') >>> command = context.get_action('get_assets') >>> command() >>> # ['/some/asset1.tif', '/some/asset2.tif', '/some/asset2.tif']
Example
>>> # If an action is meant to return back an iterable object and the >>> # action that it gets back is None, that can cause immediate problems >>> # >>> context = Context('/some/context') >>> command = context.get_action('get_assets') # Returns None >>> for asset in command(): >>> print(asset) >>> # The above code will TypeError error if get_action returns None
Example
>>> # The best you can do is this >>> context = Context('/some/context') >>> command = context.get_action('get_assets') or lambda: [] >>> for asset in command(): >>> print(asset) >>> # The above code will not error but it's pretty verbose compared to >>> # what we're actually trying to accomplish.
Example
>>> # Here is (IMO) the best solution >>> context = Context('/some/context') >>> find = finder.Find(context) >>> # Returns [] even if get_assets isn't defined >>> # because get_assets is listed in Finder(context).defaults >>> # >>> for asset in find.get_assets(): >>> print(asset)
-
classmethod
add_to_defaults
(name, value, hierarchy=None)[source]¶ Add default value if an Action name is missing.
Parameters: - name (str) – The name of the Action to add a default value for.
- value – The object to add as the default return value for a missing Action.
- hierarchy (
tuple[str] or str
, optional) – The location to put these default values. If no hierarchy is given, (‘default’, ) is used, instead.
-
defaults
= defaultdict(None, {('default',): {}})¶
-
classmethod