From 8ad1831b94afa92bd2992cc4ec938051cfe309fa Mon Sep 17 00:00:00 2001 From: Alexis Date: Fri, 21 Aug 2020 11:43:13 +0200 Subject: [PATCH] api: abstract_paths_from_template sequence key - ignore only format_spec format --- python/tank/api.py | 17 ++++++++++++++--- python/tank/templatekey.py | 16 ++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/python/tank/api.py b/python/tank/api.py index 386c24e3e..9beadc985 100644 --- a/python/tank/api.py +++ b/python/tank/api.py @@ -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 @@ -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 diff --git a/python/tank/templatekey.py b/python/tank/templatekey.py index 4b48d6e9d..7d124b9d9 100644 --- a/python/tank/templatekey.py +++ b/python/tank/templatekey.py @@ -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: @@ -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) @@ -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