Skip to content

Commit

Permalink
api: abstract_paths_from_template sequence key - ignore only format_s…
Browse files Browse the repository at this point in the history
…pec format
  • Loading branch information
Alexis committed Aug 21, 2020
1 parent e7db0fe commit 8ad1831
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
17 changes: 14 additions & 3 deletions python/tank/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .errors import TankError, TankMultipleMatchingTemplatesError
from .path_cache import PathCache
from .template import read_templates
from .templatekey import SequenceKey
from . import constants
from . import pipelineconfig
from . import pipelineconfig_utils
Expand Down Expand Up @@ -688,10 +689,20 @@ def abstract_paths_from_template(self, template, fields):
k.name for k in search_template.keys.values() if k.is_abstract
]

# skip abstract SequenceKey declared as format_spec_format: "FORMAT:"
# then we can list properly existing paths
skip_keys = []
for k in st_abstract_key_names:
if k not in fields:
continue
if not isinstance(k, SequenceKey):
continue
if not k.is_framespec_format(fields[k]):
continue
skip_keys.append(k)

# now carry out a regular search based on the template
# skip abstract keys to fetch paths in case of special value
# like SequenceKey with "FORMAT:" value
found_files = self.paths_from_template(search_template, fields, skip_keys=st_abstract_key_names)
found_files = self.paths_from_template(search_template, fields, skip_keys=skip_keys)

# now collapse down the search matches for any abstract fields,
# and add the leaf level if necessary
Expand Down
16 changes: 6 additions & 10 deletions python/tank/templatekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,7 @@ def validate(self, value):
error_msg += "Valid frame specs: %s\n" % str(self._frame_specs)
error_msg += "Valid format strings: %s\n" % full_format_strings

if isinstance(value, six.string_types) and value.startswith(
self.FRAMESPEC_FORMAT_INDICATOR
):
if self.is_framespec_format(value):
# FORMAT: YXZ string - check that XYZ is in VALID_FORMAT_STRINGS
pattern = self._extract_format_string(value)
if pattern in self.VALID_FORMAT_STRINGS:
Expand Down Expand Up @@ -1142,11 +1140,11 @@ def validate(self, value):
else:
return super(SequenceKey, self).validate(value)

def _as_string(self, value):
def is_framespec_format(self, value):
return isinstance(value, six.string_types) and value.startswith(self.FRAMESPEC_FORMAT_INDICATOR)

if isinstance(value, six.string_types) and value.startswith(
self.FRAMESPEC_FORMAT_INDICATOR
):
def _as_string(self, value):
if self.is_framespec_format(value):
# this is a FORMAT: XYZ - convert it to the proper resolved frame spec
pattern = self._extract_format_string(value)
return self._resolve_frame_spec(pattern, self.format_spec)
Expand Down Expand Up @@ -1180,9 +1178,7 @@ def _extract_format_string(self, value):
"""
Returns XYZ given the string "FORMAT: XYZ"
"""
if isinstance(value, six.string_types) and value.startswith(
self.FRAMESPEC_FORMAT_INDICATOR
):
if self.is_framespec_format(value):
pattern = value.replace(self.FRAMESPEC_FORMAT_INDICATOR, "").strip()
else:
# passthrough
Expand Down

0 comments on commit 8ad1831

Please sign in to comment.