nomenclator.template¶
-
nomenclator.template.
fetch_resolved_tokens
(path, pattern, default_expression='[\\w_.-]+', match_start=True, match_end=True)[source]¶ Return resolved tokens from path and pattern if compatible.
For instance:
>>> fetch_resolved_tokens( ... "/path/my_project/ep002/sh003/scripts", ... "/path/{project}/{episode:ep\d+}/{shot:sh\d+}/scripts" ... ) { "project": "my_project", "episode": "ep002", "shot": "sh003" }
If the path and pattern are compatible, but the pattern does not specify any tokens, an empty mapping will be returned.
>>> fetch_resolved_tokens( ... "/path/project/scripts", ... "/path/project/scripts" ... ) {}
If the path and pattern are not compatible, None is returned.
>>> fetch_resolved_tokens( ... "/path/my_project/build/character/scripts", ... "/path/{project}/{episode:ep\d+}/{shot:sh\d+}/scripts" ... ) None
Parameters: - path – Path to compare template pattern to.
- pattern – String representing a template pattern path, with or without tokens.
- default_expression – Regular expression pattern to use for tokens
when no expression is specified. Default is
nomanclator.symbol.DEFAULT_EXPRESSION
. - match_start – Indicate whether the path should match against the start of the pattern. Default is True.
- match_end – Indicate whether the path should match against the end of the pattern. Default is True.
Returns: Mapping regrouping resolved token value associated with their name, or None if the path and pattern are not compatible.
-
nomenclator.template.
construct_regexp
(pattern, default_expression='[\\w_.-]+', match_start=True, match_end=True)[source]¶ Return template pattern converted into a regular expression.
For instance:
>>> construct_regexp("/path/{project}/{episode:ep\d+}") re.compile(r"^/path/(?P<project>[\w_.-]+)/(?P<episode>ep\d+)$")
Parameters: - pattern – String representing a template pattern path, with or without tokens.
- default_expression – Regular expression pattern to use for tokens
when no expression is specified. Default is
nomanclator.symbol.DEFAULT_TOKEN_EXPRESSION
. - match_start – Indicate whether the regular expression returned should match against the start of an input. Default is True.
- match_end – Indicate whether the regular expression returned should match against the end of an input. Default is True.
Returns: Compiled regular expression.
-
nomenclator.template.
sanitize_pattern
(pattern)[source]¶ Return template pattern with all special characters escaped.
Tokens name and expressions are returned unchanged.
For instance:
>>> sanitize_pattern("/path*/{job:J_.*}") "/path\*/{job:J_.*}"
Parameters: pattern – String representing a template pattern path, with or without tokens. Returns: Sanitized string template pattern.
-
nomenclator.template.
generate_scene_name
(pattern, suffix, append_username=False, token_mapping=None)[source]¶ Generate scene name from pattern using a mapping of resolved tokens.
Parameters: - pattern – String representing a template base, with or without tokens.
- suffix – Suffix to apply for the generated name (e.g. “nk” or “hrox”).
- append_username – Indicate whether username should be appended to base name. Default is False.
- token_mapping – Mapping regrouping resolved token values associated with their name. Default is None.
Returns: String name.
Raise: exc:ValueError if a token within the pattern does not have any value within the token map.
-
nomenclator.template.
generate_output_name
(pattern, suffix, append_passname_to_subfolder=False, append_passname=False, append_colorspace=False, append_username=False, multi_views=False, token_mapping=None)[source]¶ Generate output name from pattern using a mapping of resolved tokens.
Parameters: - pattern – String representing a template base, with or without tokens.
- suffix – Suffix to apply for the generated name (e.g. “exr”).
- append_passname_to_subfolder – Indicate whether passname should be appended to sub-folder. Default is False.
- append_passname – Indicate whether passname should be appended to base name. Default is False.
- append_colorspace – Indicate whether colorspace should be appended to base name. Default is False.
- append_username – Indicate whether username should be appended to base name. Default is False.
- multi_views – Indicate whether the view should be appended to base name with the pattern ‘%V’. Default is False.
- token_mapping – Mapping regrouping resolved token values associated with their name. Default is None.
Returns: String name.
Raise: exc:ValueError if a token within the pattern does not have any value within the token map.
-
nomenclator.template.
resolve
(pattern, token_mapping)[source]¶ Return the resolved name for pattern.
Parameters: - pattern – String representing a template pattern, with or without tokens.
- token_mapping – Mapping regrouping resolved token values associated with their name.
Returns: String name.
Raise: exc:ValueError if a token within the pattern does not have any value within the token map.