mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
✨ add functions for working with aliases
this might be temporary location until better is found
This commit is contained in:
parent
96e7af6b4b
commit
8acac8a3ba
1 changed files with 50 additions and 0 deletions
50
client/ayon_core/pipeline/product_type_aliases.py
Normal file
50
client/ayon_core/pipeline/product_type_aliases.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""Tools for working with product type aliases."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from ayon_core.settings import get_project_settings
|
||||
from ayon_core.pipeline import get_current_project_name
|
||||
|
||||
def get_product_type_aliases(
|
||||
project_settings: Optional[dict] = None) -> dict[str, str]:
|
||||
"""Get product type aliases from project settings.
|
||||
|
||||
Args:
|
||||
project_settings (Optional[dict], optional): Project settings.
|
||||
Defaults to None. If not passed, the current project settings
|
||||
will be used.
|
||||
|
||||
Returns:
|
||||
dict[str, str]: A dictionary of product type aliases.
|
||||
|
||||
"""
|
||||
if project_settings is None:
|
||||
project_settings = get_project_settings(
|
||||
project_name=get_current_project_name())
|
||||
|
||||
product_type_aliases_raw = project_settings.get("product_type_aliases", {})
|
||||
if not product_type_aliases_raw:
|
||||
return {}
|
||||
|
||||
return product_type_aliases_raw.get("aliases", {})
|
||||
|
||||
|
||||
def get_alias_for_product_type(
|
||||
product_type: str,
|
||||
project_settings: Optional[dict] = None
|
||||
) -> Optional[str]:
|
||||
"""Get the alias for a product type.
|
||||
|
||||
Args:
|
||||
product_type (str): The product type to get the alias for.
|
||||
project_settings (Optional[dict], optional): Project settings.
|
||||
Defaults to None. If not passed, the current project settings
|
||||
will be used.
|
||||
|
||||
Returns:
|
||||
str: The alias for the product type. If no alias is found,
|
||||
None is returned.
|
||||
"""
|
||||
product_type_aliases = get_product_type_aliases(project_settings)
|
||||
return product_type_aliases.get(product_type)
|
||||
Loading…
Add table
Add a link
Reference in a new issue