mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
wrap optional arguments into wrappers
This commit is contained in:
parent
1d40243df5
commit
646f3bedd4
4 changed files with 877 additions and 467 deletions
|
|
@ -1,5 +1,30 @@
|
|||
from .exceptions import MissingMethodsError
|
||||
from .workfiles import IWorkfileHost, WorkfileInfo, PublishedWorkfileInfo
|
||||
from .workfiles import (
|
||||
IWorkfileHost,
|
||||
WorkfileInfo,
|
||||
PublishedWorkfileInfo,
|
||||
|
||||
OpenWorkfileOptionalData,
|
||||
ListWorkfilesOptionalData,
|
||||
ListPublishedWorkfilesOptionalData,
|
||||
SaveWorkfileOptionalData,
|
||||
CopyWorkfileOptionalData,
|
||||
CopyPublishedWorkfileOptionalData,
|
||||
|
||||
get_open_workfile_context,
|
||||
get_list_workfiles_context,
|
||||
get_list_published_workfiles_context,
|
||||
get_save_workfile_context,
|
||||
get_copy_workfile_context,
|
||||
get_copy_repre_workfile_context,
|
||||
|
||||
OpenWorkfileContext,
|
||||
ListWorkfilesContext,
|
||||
ListPublishedWorkfilesContext,
|
||||
SaveWorkfileContext,
|
||||
CopyWorkfileContext,
|
||||
CopyPublishedWorkfileContext,
|
||||
)
|
||||
from .interfaces import (
|
||||
IPublishHost,
|
||||
INewPublisher,
|
||||
|
|
@ -14,6 +39,27 @@ __all__ = (
|
|||
"WorkfileInfo",
|
||||
"PublishedWorkfileInfo",
|
||||
|
||||
"OpenWorkfileOptionalData",
|
||||
"ListWorkfilesOptionalData",
|
||||
"ListPublishedWorkfilesOptionalData",
|
||||
"SaveWorkfileOptionalData",
|
||||
"CopyWorkfileOptionalData",
|
||||
"CopyPublishedWorkfileOptionalData",
|
||||
|
||||
"get_open_workfile_context",
|
||||
"get_list_workfiles_context",
|
||||
"get_list_published_workfiles_context",
|
||||
"get_save_workfile_context",
|
||||
"get_copy_workfile_context",
|
||||
"get_copy_repre_workfile_context",
|
||||
|
||||
"OpenWorkfileContext",
|
||||
"ListWorkfilesContext",
|
||||
"ListPublishedWorkfilesContext",
|
||||
"SaveWorkfileContext",
|
||||
"CopyWorkfileContext",
|
||||
"CopyPublishedWorkfileContext",
|
||||
|
||||
"IPublishHost",
|
||||
"INewPublisher",
|
||||
"ILoadHost",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,6 +10,12 @@ from ayon_api.operations import OperationsSession
|
|||
|
||||
from ayon_core.lib import filter_profiles, get_ayon_username
|
||||
from ayon_core.settings import get_project_settings
|
||||
from ayon_core.host.interfaces import (
|
||||
SaveWorkfileOptionalData,
|
||||
OpenWorkfileOptionalData,
|
||||
CopyWorkfileOptionalData,
|
||||
CopyPublishedWorkfileOptionalData,
|
||||
)
|
||||
|
||||
from .path_resolving import get_workfile_template_key
|
||||
|
||||
|
|
@ -303,9 +309,8 @@ def open_workfile(
|
|||
filepath: str,
|
||||
folder_entity: dict[str, Any],
|
||||
task_entity: dict[str, Any],
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
project_settings: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional["Anatomy"] = None,
|
||||
*,
|
||||
prepared_data: Optional[OpenWorkfileOptionalData] = None,
|
||||
):
|
||||
from ayon_core.pipeline.context_tools import registered_host
|
||||
|
||||
|
|
@ -315,9 +320,7 @@ def open_workfile(
|
|||
filepath,
|
||||
folder_entity,
|
||||
task_entity,
|
||||
project_entity=project_entity,
|
||||
project_settings=project_settings,
|
||||
anatomy=anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -329,11 +332,7 @@ def save_current_workfile_to(
|
|||
version: Optional[int] = None,
|
||||
comment: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
rootless_path: Optional[str] = None,
|
||||
workfile_entities: Optional[list[dict[str, Any]]] = None,
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
project_settings: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional["Anatomy"] = None,
|
||||
prepared_data: Optional[SaveWorkfileOptionalData] = None,
|
||||
) -> None:
|
||||
"""Save current workfile to new location or context.
|
||||
|
||||
|
|
@ -344,16 +343,8 @@ def save_current_workfile_to(
|
|||
version (Optional[int]): Workfile version.
|
||||
comment (optional[str]): Workfile comment.
|
||||
description (Optional[str]): Workfile description.
|
||||
rootless_path (Optional[str]): Rootless path of the workfile. Is
|
||||
calculated if not passed in.
|
||||
workfile_entities (Optional[list[dict[str, Any]]]): Pre-fetched
|
||||
workfile entities related to the task.
|
||||
project_entity (Optional[dict[str, Any]]): Project entity used for
|
||||
rootless path calculation.
|
||||
project_settings (Optional[dict[str, Any]]): Project settings used for
|
||||
rootless path calculation.
|
||||
anatomy (Optional[Anatomy]): Project anatomy used for rootless
|
||||
path calculation.
|
||||
prepared_data (Optional[SaveWorkfileOptionalData]): Prepared data
|
||||
for speed enhancements.
|
||||
|
||||
"""
|
||||
from ayon_core.pipeline.context_tools import registered_host
|
||||
|
|
@ -366,11 +357,7 @@ def save_current_workfile_to(
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
project_entity=project_entity,
|
||||
project_settings=project_settings,
|
||||
anatomy=anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -380,11 +367,7 @@ def save_workfile_with_current_context(
|
|||
version: Optional[int] = None,
|
||||
comment: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
rootless_path: Optional[str] = None,
|
||||
workfile_entities: Optional[list[dict[str, Any]]] = None,
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
project_settings: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional["Anatomy"] = None,
|
||||
prepared_data: Optional[SaveWorkfileOptionalData] = None,
|
||||
) -> None:
|
||||
"""Save current workfile to new location using current context.
|
||||
|
||||
|
|
@ -396,16 +379,8 @@ def save_workfile_with_current_context(
|
|||
version (Optional[int]): Workfile version.
|
||||
comment (optional[str]): Workfile comment.
|
||||
description (Optional[str]): Workfile description.
|
||||
rootless_path (Optional[str]): Rootless path of the workfile. Is
|
||||
calculated if not passed in.
|
||||
workfile_entities (Optional[list[dict[str, Any]]]): Pre-fetched
|
||||
workfile entities related to the task.
|
||||
project_entity (Optional[dict[str, Any]]): Project entity used for
|
||||
rootless path calculation.
|
||||
project_settings (Optional[dict[str, Any]]): Project settings used for
|
||||
rootless path calculation.
|
||||
anatomy (Optional[Anatomy]): Project anatomy used for rootless
|
||||
path calculation.
|
||||
prepared_data (Optional[SaveWorkfileOptionalData]): Prepared data
|
||||
for speed enhancements.
|
||||
|
||||
"""
|
||||
from ayon_core.pipeline.context_tools import registered_host
|
||||
|
|
@ -430,11 +405,7 @@ def save_workfile_with_current_context(
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
project_entity=project_entity,
|
||||
project_settings=project_settings,
|
||||
anatomy=anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -447,11 +418,7 @@ def copy_and_open_workfile(
|
|||
version: Optional[int] = None,
|
||||
comment: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
rootless_path: Optional[str] = None,
|
||||
workfile_entities: Optional[list[dict[str, Any]]] = None,
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
project_settings: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional["Anatomy"] = None,
|
||||
prepared_data: Optional[CopyWorkfileOptionalData] = None,
|
||||
) -> None:
|
||||
"""Copy workfile to new location and open it.
|
||||
|
||||
|
|
@ -463,16 +430,8 @@ def copy_and_open_workfile(
|
|||
version (Optional[int]): Workfile version.
|
||||
comment (optional[str]): Workfile comment.
|
||||
description (Optional[str]): Workfile description.
|
||||
rootless_path (Optional[str]): Rootless path of the workfile. Is
|
||||
calculated if not passed in.
|
||||
workfile_entities (Optional[list[dict[str, Any]]]): Pre-fetched
|
||||
workfile entities related to the task.
|
||||
project_entity (Optional[dict[str, Any]]): Project entity used for
|
||||
rootless path calculation.
|
||||
project_settings (Optional[dict[str, Any]]): Project settings used for
|
||||
rootless path calculation.
|
||||
anatomy (Optional[Anatomy]): Project anatomy used for rootless
|
||||
path calculation.
|
||||
prepared_data (Optional[CopyWorkfileOptionalData]): Prepared data
|
||||
for speed enhancements.
|
||||
|
||||
"""
|
||||
from ayon_core.pipeline.context_tools import registered_host
|
||||
|
|
@ -486,18 +445,14 @@ def copy_and_open_workfile(
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
project_entity=project_entity,
|
||||
project_settings=project_settings,
|
||||
anatomy=anatomy,
|
||||
open_workfile=True,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
|
||||
def copy_and_open_workfile_representation(
|
||||
src_project_name: str,
|
||||
representation_id: str,
|
||||
representation_entity: dict[str, Any],
|
||||
workfile_path: str,
|
||||
folder_entity: dict[str, Any],
|
||||
task_entity: dict[str, Any],
|
||||
|
|
@ -505,50 +460,25 @@ def copy_and_open_workfile_representation(
|
|||
version: Optional[int] = None,
|
||||
comment: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
rootless_path: Optional[str] = None,
|
||||
representation_entity: Optional[dict[str, Any]] = None,
|
||||
representation_path: Optional[str] = None,
|
||||
workfile_entities: Optional[list[dict[str, Any]]] = None,
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
project_settings: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional["Anatomy"] = None,
|
||||
src_anatomy: Optional["Anatomy"] = None,
|
||||
prepared_data: Optional[CopyPublishedWorkfileOptionalData] = None,
|
||||
) -> None:
|
||||
"""Copy workfile to new location and open it.
|
||||
|
||||
Args:
|
||||
src_project_name (str): Project name where representation is stored.
|
||||
representation_id (str): Source representation id.
|
||||
representation_entity (dict[str, Any]): Representation entity.
|
||||
workfile_path (str): Destination workfile path.
|
||||
folder_entity (dict[str, Any]): Target folder entity.
|
||||
task_entity (dict[str, Any]): Target task entity.
|
||||
version (Optional[int]): Workfile version.
|
||||
comment (optional[str]): Workfile comment.
|
||||
description (Optional[str]): Workfile description.
|
||||
rootless_path (Optional[str]): Rootless path of the workfile. Is
|
||||
calculated if not passed in.
|
||||
representation_entity (Optional[dict[str, Any]]): Representation
|
||||
entity. If not provided, it will be fetched from the server.
|
||||
representation_path (Optional[str]): Path to the representation.
|
||||
Calculated if not provided.
|
||||
workfile_entities (Optional[list[dict[str, Any]]]): Pre-fetched
|
||||
workfile entities related to the task.
|
||||
project_entity (Optional[dict[str, Any]]): Project entity used for
|
||||
rootless path calculation.
|
||||
project_settings (Optional[dict[str, Any]]): Project settings used for
|
||||
rootless path calculation.
|
||||
anatomy (Optional[Anatomy]): Project anatomy used for rootless
|
||||
path calculation.
|
||||
prepared_data (Optional[CopyPublishedWorkfileOptionalData]): Prepared data
|
||||
for speed enhancements.
|
||||
|
||||
"""
|
||||
from ayon_core.pipeline.context_tools import registered_host
|
||||
|
||||
if representation_entity is None:
|
||||
representation_entity = ayon_api.get_representation_by_id(
|
||||
src_project_name,
|
||||
representation_id,
|
||||
)
|
||||
|
||||
host = registered_host()
|
||||
host.copy_workfile_representation(
|
||||
src_project_name,
|
||||
|
|
@ -559,14 +489,8 @@ def copy_and_open_workfile_representation(
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
project_settings=project_settings,
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
src_anatomy=src_anatomy,
|
||||
src_representation_path=representation_path,
|
||||
open_workfile=open_workfile,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ from ayon_core.host import (
|
|||
WorkfileInfo,
|
||||
PublishedWorkfileInfo,
|
||||
)
|
||||
from ayon_core.host.interfaces import (
|
||||
OpenWorkfileOptionalData,
|
||||
ListWorkfilesOptionalData,
|
||||
ListPublishedWorkfilesOptionalData,
|
||||
SaveWorkfileOptionalData,
|
||||
CopyWorkfileOptionalData,
|
||||
CopyPublishedWorkfileOptionalData,
|
||||
)
|
||||
from ayon_core.pipeline.template_data import (
|
||||
get_template_data,
|
||||
get_task_template_data,
|
||||
|
|
@ -142,6 +150,7 @@ class WorkfilesModel:
|
|||
filepath = os.path.join(workdir, filename)
|
||||
rootless_path = f"{rootless_workdir}/{filename}"
|
||||
project_name = self._controller.get_current_project_name()
|
||||
project_entity = self._controller.get_project_entity(project_name)
|
||||
folder_entity = self._controller.get_folder_entity(
|
||||
project_name, folder_id
|
||||
)
|
||||
|
|
@ -149,6 +158,13 @@ class WorkfilesModel:
|
|||
project_name, task_id
|
||||
)
|
||||
|
||||
prepared_data = SaveWorkfileOptionalData(
|
||||
project_entity=project_entity,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
project_settings=self._controller.project_settings,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=self.get_workfile_entities(task_id),
|
||||
)
|
||||
failed = False
|
||||
try:
|
||||
save_current_workfile_to(
|
||||
|
|
@ -158,13 +174,7 @@ class WorkfilesModel:
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=self.get_workfile_entities(task_id),
|
||||
project_entity=self._controller.get_project_entity(
|
||||
project_name
|
||||
),
|
||||
project_settings=self._controller.project_settings,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
self._update_workfile_info(
|
||||
task_id, rootless_path, description
|
||||
|
|
@ -198,37 +208,38 @@ class WorkfilesModel:
|
|||
self._emit_event("copy_representation.started")
|
||||
|
||||
project_name = self._project_name
|
||||
project_entity = self._controller.get_project_entity(project_name)
|
||||
folder_entity = self._controller.get_folder_entity(
|
||||
self._project_name, folder_id
|
||||
project_name, folder_id
|
||||
)
|
||||
task_entity = self._controller.get_task_entity(
|
||||
self._project_name, task_id
|
||||
project_name, task_id
|
||||
)
|
||||
repre_entity = self._repre_by_id.get(representation_id)
|
||||
dst_filepath = os.path.join(workdir, filename)
|
||||
rootless_path = f"{rootless_workdir}/{filename}"
|
||||
|
||||
prepared_data = CopyPublishedWorkfileOptionalData(
|
||||
project_entity=project_entity,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
project_settings=self._controller.project_settings,
|
||||
rootless_path=rootless_path,
|
||||
representation_path=representation_filepath,
|
||||
workfile_entities=self.get_workfile_entities(task_id),
|
||||
src_anatomy=self._controller.project_anatomy,
|
||||
)
|
||||
failed = False
|
||||
workfile_entities = self.get_workfile_entities(task_id)
|
||||
try:
|
||||
copy_and_open_workfile_representation(
|
||||
project_name,
|
||||
representation_id,
|
||||
repre_entity,
|
||||
dst_filepath,
|
||||
folder_entity,
|
||||
task_entity,
|
||||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
representation_entity=repre_entity,
|
||||
representation_path=representation_filepath,
|
||||
workfile_entities=workfile_entities,
|
||||
project_entity=self._controller.get_project_entity(
|
||||
project_name
|
||||
),
|
||||
project_settings=self._controller.project_settings,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
self._update_workfile_info(
|
||||
task_id, rootless_path, description
|
||||
|
|
@ -271,6 +282,14 @@ class WorkfilesModel:
|
|||
workfile_entities = self.get_workfile_entities(task_id)
|
||||
rootless_path = f"{rootless_workdir}/{filename}"
|
||||
workfile_path = os.path.join(workdir, filename)
|
||||
|
||||
prepared_data = CopyWorkfileOptionalData(
|
||||
project_entity=project_entity,
|
||||
project_settings=self._controller.project_settings,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
)
|
||||
failed = False
|
||||
try:
|
||||
copy_and_open_workfile(
|
||||
|
|
@ -281,11 +300,7 @@ class WorkfilesModel:
|
|||
version=version,
|
||||
comment=comment,
|
||||
description=description,
|
||||
rootless_path=rootless_path,
|
||||
workfile_entities=workfile_entities,
|
||||
project_entity=project_entity,
|
||||
project_settings=self._controller.project_settings,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
|
||||
except Exception:
|
||||
|
|
@ -571,12 +586,12 @@ class WorkfilesModel:
|
|||
project_name = self._project_name
|
||||
anatomy = self._controller.project_anatomy
|
||||
|
||||
product_entities = ayon_api.get_products(
|
||||
product_entities = list(ayon_api.get_products(
|
||||
project_name,
|
||||
folder_ids={folder_id},
|
||||
product_types={"workfile"},
|
||||
fields={"id", "name"}
|
||||
)
|
||||
))
|
||||
|
||||
version_entities = []
|
||||
product_ids = {product["id"] for product in product_entities}
|
||||
|
|
@ -599,13 +614,20 @@ class WorkfilesModel:
|
|||
repre_entity["id"]: repre_entity
|
||||
for repre_entity in repre_entities
|
||||
})
|
||||
project_entity = self._controller.get_project_entity(project_name)
|
||||
|
||||
prepared_data = ListPublishedWorkfilesOptionalData(
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
project_settings=self._controller.project_settings,
|
||||
product_entities=product_entities,
|
||||
version_entities=version_entities,
|
||||
repre_entities=repre_entities,
|
||||
)
|
||||
cache.update_data(self._host.list_published_workfiles(
|
||||
project_name,
|
||||
folder_id,
|
||||
anatomy=anatomy,
|
||||
version_entities=version_entities,
|
||||
repre_entities=repre_entities,
|
||||
prepared_data=prepared_data,
|
||||
))
|
||||
|
||||
items = cache.get_data()
|
||||
|
|
@ -638,13 +660,21 @@ class WorkfilesModel:
|
|||
def _open_workfile(self, folder_id: str, task_id: str, filepath: str):
|
||||
# TODO move to workfiles pipeline
|
||||
project_name = self._project_name
|
||||
project_entity = self._controller.get_project_entity(project_name)
|
||||
folder_entity = self._controller.get_folder_entity(
|
||||
project_name, folder_id
|
||||
)
|
||||
task_entity = self._controller.get_task_entity(
|
||||
project_name, task_id
|
||||
)
|
||||
open_workfile(filepath, folder_entity, task_entity)
|
||||
prepared_data = OpenWorkfileOptionalData(
|
||||
project_entity=project_entity,
|
||||
anatomy=self._controller.project_anatomy,
|
||||
project_settings=self._controller.project_settings,
|
||||
)
|
||||
open_workfile(
|
||||
filepath, folder_entity, task_entity, prepared_data=prepared_data
|
||||
)
|
||||
self._update_current_context(
|
||||
folder_id, folder_entity["path"], task_entity["name"]
|
||||
)
|
||||
|
|
@ -739,15 +769,19 @@ class WorkfilesModel:
|
|||
fill_data = self._prepare_fill_data(folder_id, task_id)
|
||||
template_key = self._get_template_key(fill_data)
|
||||
|
||||
prepared_data = ListWorkfilesOptionalData(
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
project_settings=project_settings,
|
||||
template_key=template_key,
|
||||
workfile_entities=workfile_entities,
|
||||
)
|
||||
|
||||
items = self._host.list_workfiles(
|
||||
self._project_name,
|
||||
folder_entity,
|
||||
task_entity,
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
template_key=template_key,
|
||||
project_settings=project_settings,
|
||||
workfile_entities=workfile_entities,
|
||||
prepared_data=prepared_data,
|
||||
)
|
||||
cache.update_data(items)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue