mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 08:54:53 +01:00
fixed asset name lookup
This commit is contained in:
parent
d119373dc1
commit
0257e04192
1 changed files with 32 additions and 6 deletions
|
|
@ -21,19 +21,23 @@ class CollectMatchingAssetToInstance(pyblish.api.InstancePlugin):
|
|||
version_regex = re.compile(r"^(.+)_v([0-9]+)$")
|
||||
|
||||
def process(self, instance):
|
||||
source_file = os.path.basename(instance.data["source"]).lower()
|
||||
source_filename = self.get_source_filename(instance)
|
||||
self.log.info("Looking for asset document for file \"{}\"".format(
|
||||
instance.data["source"]
|
||||
source_filename
|
||||
))
|
||||
asset_name = os.path.splitext(source_filename)[0].lower()
|
||||
|
||||
asset_docs_by_name = self.selection_children_by_name(instance)
|
||||
|
||||
version_number = None
|
||||
# Always first check if source filename is in assets
|
||||
matching_asset_doc = asset_docs_by_name.get(source_file)
|
||||
matching_asset_doc = asset_docs_by_name.get(asset_name)
|
||||
if matching_asset_doc is None:
|
||||
# Check if source file contain version in name
|
||||
regex_result = self.version_regex.findall(source_file)
|
||||
self.log.debug((
|
||||
"Asset doc by \"{}\" was not found trying version regex."
|
||||
).format(asset_name))
|
||||
regex_result = self.version_regex.findall(asset_name)
|
||||
if regex_result:
|
||||
asset_name, _version_number = regex_result[0]
|
||||
matching_asset_doc = asset_docs_by_name.get(asset_name)
|
||||
|
|
@ -42,16 +46,19 @@ class CollectMatchingAssetToInstance(pyblish.api.InstancePlugin):
|
|||
|
||||
if matching_asset_doc is None:
|
||||
for asset_name_low, asset_doc in asset_docs_by_name.items():
|
||||
if asset_name_low in source_file:
|
||||
if asset_name_low in asset_name:
|
||||
matching_asset_doc = asset_doc
|
||||
break
|
||||
|
||||
if not matching_asset_doc:
|
||||
self.log.debug("Available asset names {}".format(
|
||||
str(list(asset_docs_by_name.keys()))
|
||||
))
|
||||
# TODO better error message
|
||||
raise AssertionError((
|
||||
"Filename \"{}\" does not match"
|
||||
" any name of asset documents in database for your selection."
|
||||
).format(instance.data["source"]))
|
||||
).format(source_filename))
|
||||
|
||||
instance.data["asset"] = matching_asset_doc["name"]
|
||||
instance.data["assetEntity"] = matching_asset_doc
|
||||
|
|
@ -62,6 +69,25 @@ class CollectMatchingAssetToInstance(pyblish.api.InstancePlugin):
|
|||
f"Matching asset found: {pformat(matching_asset_doc)}"
|
||||
)
|
||||
|
||||
def get_source_filename(self, instance):
|
||||
if instance.data["family"] == "background_batch":
|
||||
return os.path.basename(instance.data["source"])
|
||||
|
||||
if len(instance.data["representations"]) != 1:
|
||||
raise ValueError((
|
||||
"Implementation bug: Instance data contain"
|
||||
" more than one representation."
|
||||
))
|
||||
|
||||
repre = instance.data["representations"][0]
|
||||
repre_files = repre["files"]
|
||||
if not isinstance(repre_files, str):
|
||||
raise ValueError((
|
||||
"Implementation bug: Instance's representation contain"
|
||||
" unexpected value (expected single file). {}"
|
||||
).format(str(repre_files)))
|
||||
return repre_files
|
||||
|
||||
def selection_children_by_name(self, instance):
|
||||
storing_key = "childrenDocsForSelection"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue