Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ayon_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
get_workfiles_info,
get_workfile_info,
get_workfile_info_by_id,
delete_workfile_info,
update_workfile_info,
get_full_link_type_name,
get_link_types,
get_link_type,
Expand Down Expand Up @@ -488,6 +490,8 @@
"get_workfiles_info",
"get_workfile_info",
"get_workfile_info_by_id",
"delete_workfile_info",
"update_workfile_info",
"get_full_link_type_name",
"get_link_types",
"get_link_type",
Expand Down
69 changes: 69 additions & 0 deletions ayon_api/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6197,6 +6197,75 @@ def get_workfile_info_by_id(
)


def delete_workfile_info(
project_name: str,
workfile_id: str,
) -> None:
"""Delete workfile entity on server.

Args:
project_name (str): Project name.
workfile_id (str): Workfile id to delete.

"""
con = get_server_api_connection()
return con.delete_workfile_info(
project_name=project_name,
workfile_id=workfile_id,
)


def update_workfile_info(
project_name: str,
workfile_id: str,
path: Optional[str] = None,
task_id: Optional[str] = None,
attrib: Optional[dict[str, Any]] = None,
data: Optional[dict[str, Any]] = None,
tags: Optional[Iterable[str]] = None,
status: Optional[str] = None,
active: Optional[bool] = None,
thumbnail_id: Optional[str] = NOT_SET,
created_by: Optional[str] = None,
updated_by: Optional[str] = None,
) -> None:
"""Update workfile entity on server.

Update of ``attrib`` does change only passed attributes. If you want
to unset value, use ``None``.

Args:
project_name (str): Project name.
workfile_id (str): Workfile id.
path (Optional[str]): New rootless workfile path..
task_id (Optional[str]): New parent task id.
attrib (Optional[dict[str, Any]]): New attributes.
data (Optional[dict[str, Any]]): New data.
tags (Optional[Iterable[str]]): New tags.
status (Optional[str]): New status.
active (Optional[bool]): New active state.
thumbnail_id (Optional[str]): New thumbnail id.
created_by (Optional[str]): New created by username.
updated_by (Optional[str]): New updated by username.

"""
con = get_server_api_connection()
return con.update_workfile_info(
project_name=project_name,
workfile_id=workfile_id,
path=path,
task_id=task_id,
attrib=attrib,
data=data,
tags=tags,
status=status,
active=active,
thumbnail_id=thumbnail_id,
created_by=created_by,
updated_by=updated_by,
)


def get_full_link_type_name(
link_type_name: str,
input_type: str,
Expand Down
83 changes: 81 additions & 2 deletions ayon_api/_api_helpers/workfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import warnings
import typing
from typing import Optional, Iterable, Generator
from typing import Optional, Iterable, Generator, Any

from ayon_api.graphql_queries import workfiles_info_graphql_query

from ayon_api.utils import NOT_SET
from .base import BaseServerAPI, _PLACEHOLDER

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -184,3 +184,82 @@ def get_workfile_info_by_id(
):
return workfile_info
return None

def delete_workfile_info(
self,
project_name: str,
workfile_id: str,
) -> None:
"""Delete workfile entity on server.

Args:
project_name (str): Project name.
workfile_id (str): Workfile id to delete.

"""
response = self.delete(
f"projects/{project_name}/workfiles/{workfile_id}"
)
response.raise_for_status()

def update_workfile_info(
self,
project_name: str,
workfile_id: str,
path: Optional[str] = None,
task_id: Optional[str] = None,
attrib: Optional[dict[str, Any]] = None,
data: Optional[dict[str, Any]] = None,
tags: Optional[Iterable[str]] = None,
status: Optional[str] = None,
active: Optional[bool] = None,
thumbnail_id: Optional[str] = NOT_SET,
created_by: Optional[str] = None,
updated_by: Optional[str] = None,
) -> None:
"""Update workfile entity on server.

Update of ``attrib`` does change only passed attributes. If you want
to unset value, use ``None``.

Args:
project_name (str): Project name.
workfile_id (str): Workfile id.
path (Optional[str]): New rootless workfile path..
task_id (Optional[str]): New parent task id.
attrib (Optional[dict[str, Any]]): New attributes.
data (Optional[dict[str, Any]]): New data.
tags (Optional[Iterable[str]]): New tags.
status (Optional[str]): New status.
active (Optional[bool]): New active state.
thumbnail_id (Optional[str]): New thumbnail id.
created_by (Optional[str]): New created by username.
updated_by (Optional[str]): New updated by username.

"""
update_data = {}
for key, value in (
("path", path),
("taskId", task_id),
("attrib", attrib),
("data", data),
("tags", tags),
("status", status),
("active", active),
("createdBy", created_by),
("updatedBy", updated_by),
):
if value is not None:
update_data[key] = value

for key, value in (
("thumbnailId", thumbnail_id),
):
if value is not NOT_SET:
update_data[key] = value

response = self.patch(
f"projects/{project_name}/workfiles/{workfile_id}",
**update_data
)
response.raise_for_status()