mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Refactor function update_allowed_representation_switches -> get_representation_name_aliases
This commit is contained in:
parent
50db590b08
commit
266140ad40
2 changed files with 17 additions and 18 deletions
|
|
@ -242,25 +242,25 @@ class LoaderPlugin(list):
|
|||
if hasattr(self, "_fname"):
|
||||
return self._fname
|
||||
|
||||
def update_allowed_representation_switches(self):
|
||||
"""Return a mapping from source representation names to ordered
|
||||
destination representation names to which switching is allowed if
|
||||
the source representation name does not exist for the new version.
|
||||
@classmethod
|
||||
def get_representation_name_aliases(cls, representation_name: str):
|
||||
"""Return representation names to which switching is allowed from
|
||||
the input representation name, like an alias replacement of the input
|
||||
`representation_name`.
|
||||
|
||||
For example, to allow an automated switch on update from representation
|
||||
`ma` to `mb` or `abc` if the new version does not have a `ma`
|
||||
representation you can return:
|
||||
{"ma": ["mb", "abc"]}
|
||||
`ma` to `mb` or `abc`, then when `representation_name` is `ma` return:
|
||||
["mb", "abc"]
|
||||
|
||||
The order of the names in the returned values is important, because
|
||||
if `ma` is missing and both of the replacement representations are
|
||||
present than the first one will be chosen.
|
||||
The order of the names in the returned representation names is
|
||||
important, because the first one existing under the new version will
|
||||
be chosen.
|
||||
|
||||
Returns:
|
||||
Dict[str, List[str]]: Mapping from representation names to allowed
|
||||
alias representation names switching to is allowed on update.
|
||||
List[str]: Representation names switching to is allowed on update
|
||||
if the input representation name is not found on the new version.
|
||||
"""
|
||||
return {}
|
||||
return []
|
||||
|
||||
|
||||
class ProductLoaderPlugin(LoaderPlugin):
|
||||
|
|
|
|||
|
|
@ -521,17 +521,16 @@ def update_container(container, version=-1):
|
|||
# The representation name is not found in the new version.
|
||||
# Allow updating to a 'matching' representation if the loader
|
||||
# has defined compatible update conversions
|
||||
mapping = Loader().update_allowed_representation_switches()
|
||||
switch_repre_names = mapping.get(repre_name)
|
||||
if switch_repre_names:
|
||||
repre_name_aliases = Loader.get_representation_name_aliases(repre_name)
|
||||
if repre_name_aliases:
|
||||
representations = ayon_api.get_representations(
|
||||
project_name,
|
||||
representation_names=switch_repre_names,
|
||||
representation_names=repre_name_aliases,
|
||||
version_ids=[new_version["id"]])
|
||||
representations_by_name = {
|
||||
repre["name"]: repre for repre in representations
|
||||
}
|
||||
for name in switch_repre_names:
|
||||
for name in repre_name_aliases:
|
||||
if name in representations_by_name:
|
||||
new_representation = representations_by_name[name]
|
||||
break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue