ayon_api.operations module¶
- class AbstractOperation(project_name, entity_type, session)[source]¶
Bases:
ABC
Base operation class.
Opration represent a call into database. The call can create, change or remove data.
- Parameters:
project_name (
str
) – On which project operation will happen.entity_type (
str
) – Type of entity on which change happens. e.g. ‘folder’, ‘representation’ etc.
- property entity_type¶
- property id¶
Identifier of operation.
- abstract property operation_name¶
Stringified type of operation.
- property project_name¶
- class CreateOperation(project_name, entity_type, data, session)[source]¶
Bases:
AbstractOperation
Opeartion to create an entity.
- Parameters:
project_name (
str
) – On which project operation will happen.entity_type (
str
) – Type of entity on which change happens. e.g. ‘folder’, ‘representation’ etc.data (
Dict[str, Any]
) – Data of entity that will be created.
- property con¶
- property data¶
- property entity_id¶
- operation_name = 'create'¶
- property session¶
- class DeleteOperation(project_name, entity_type, entity_id, session)[source]¶
Bases:
AbstractOperation
Opeartion to delete an entity.
- Parameters:
project_name (
str
) – On which project operation will happen.entity_type (
str
) – Type of entity on which change happens. e.g. ‘folder’, ‘representation’ etc.entity_id (
str
) – Entity id that will be removed.
- property con¶
- property entity_id¶
- operation_name = 'delete'¶
- property session¶
- class OperationsSession(con=None)[source]¶
Bases:
object
Session storing operations that should happen in an order.
At this moment does not handle anything special can be sonsidered as stupid list of operations that will happen after each other. If creation of same entity is there multiple times it’s handled in any way and entity values are not validated.
All operations must be related to single project.
- Parameters:
con (
Optional[ServerAPI]
) – Connection to server. Global connection is used if not passed.
- add(operation)[source]¶
Add operation to be processed.
- Parameters:
operation (
BaseOperation
) – Operation that should be processed.
- append(operation)[source]¶
Add operation to be processed.
- Parameters:
operation (
BaseOperation
) – Operation that should be processed.
- property con¶
- create_entity(project_name, entity_type, data, nested_id=None)[source]¶
Fast access to ‘CreateOperation’.
- Parameters:
project_name (
str
) – On which project the creation happens.entity_type (
str
) – Which entity type will be created.data (
Dicst[str, Any]
) – Entity data.nested_id (
str
) – Id of other operation from which is triggered operation -> Operations can trigger suboperations but they must be added to operations list after it’s parent is added.
- Returns:
Object of create operation.
- Return type:
- create_folder(project_name, name, folder_type=None, parent_id=None, label=None, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=None, folder_id=None)[source]¶
Create new folder.
- Parameters:
project_name (
str
) – Project name.name (
str
) – Folder name.folder_type (
Optional[str]
) – Folder type.parent_id (
Optional[str]
) – Parent folder id. Parent is project if isNone
.label (
Optional[str]
) – Label of folder.attrib (
Optional[dict[str, Any]]
) – Folder attributes.data (
Optional[dict[str, Any]]
) – Folder data.tags (
Optional[Iterable[str]]
) – Folder tags.status (
Optional[str]
) – Folder status.active (
Optional[bool]
) – Folder active state.thumbnail_id (
Optional[str]
) – Folder thumbnail id.folder_id (
Optional[str]
) – Folder id. If not passed new id is generated.
- Returns:
Object of create operation.
- Return type:
- create_product(project_name, name, product_type, folder_id, attrib=None, data=None, tags=None, status=None, active=None, product_id=None)[source]¶
Create new product.
- Parameters:
project_name (
str
) – Project name.name (
str
) – Product name.product_type (
str
) – Product type.folder_id (
str
) – Parent folder id.attrib (
Optional[dict[str, Any]]
) – Product attributes.data (
Optional[dict[str, Any]]
) – Product data.tags (
Optional[Iterable[str]]
) – Product tags.status (
Optional[str]
) – Product status.active (
Optional[bool]
) – Product active state.product_id (
Optional[str]
) – Product id. If not passed new id is generated.
- Returns:
Object of create operation.
- Return type:
- create_representation(project_name, name, version_id, files=None, attrib=None, data=None, tags=None, status=None, active=None, representation_id=None)[source]¶
Create new representation.
- Parameters:
project_name (
str
) – Project name.name (
str
) – Representation name.version_id (
str
) – Parent version id.files (
Optional[list[dict]]
) – Representation files information.attrib (
Optional[dict[str, Any]]
) – Representation attributes.data (
Optional[dict[str, Any]]
) – Representation data.tags (
Optional[Iterable[str]]
) – Representation tags.status (
Optional[str]
) – Representation status.active (
Optional[bool]
) – Representation active state.representation_id (
Optional[str]
) – Representation id. If not passed new id is generated.
- Returns:
Object of create operation.
- Return type:
- create_task(project_name, name, task_type, folder_id, label=None, assignees=None, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=None, task_id=None)[source]¶
Create new task.
- Parameters:
project_name (
str
) – Project name.name (
str
) – Folder name.task_type (
str
) – Task type.folder_id (
str
) – Parent folder id.label (
Optional[str]
) – Label of folder.assignees (
Optional[Iterable[str]]
) – Task assignees.attrib (
Optional[dict[str, Any]]
) – Task attributes.data (
Optional[dict[str, Any]]
) – Task data.tags (
Optional[Iterable[str]]
) – Task tags.status (
Optional[str]
) – Task status.active (
Optional[bool]
) – Task active state.thumbnail_id (
Optional[str]
) – Task thumbnail id.task_id (
Optional[str]
) – Task id. If not passed new id is generated.
- Returns:
Object of create operation.
- Return type:
- create_version(project_name, version, product_id, task_id=None, author=None, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=None, version_id=None)[source]¶
Create new version.
- Parameters:
project_name (
str
) – Project name.version (
int
) – Version.product_id (
str
) – Parent product id.task_id (
Optional[str]
) – Parent task id.author (
Optional[str]
) – Version author.attrib (
Optional[dict[str, Any]]
) – Version attributes.data (
Optional[dict[str, Any]]
) – Version data.tags (
Optional[Iterable[str]]
) – Version tags.status (
Optional[str]
) – Version status.active (
Optional[bool]
) – Version active state.thumbnail_id (
Optional[str]
) – Version thumbnail id.version_id (
Optional[str]
) – Version id. If not passed new id is generated.
- Returns:
Object of create operation.
- Return type:
- delete_entity(project_name, entity_type, entity_id, nested_id=None)[source]¶
Fast access to ‘DeleteOperation’.
- Returns:
Object of delete operation.
- Return type:
- delete_folder(project_name, folder_id)[source]¶
Delete folder.
- Parameters:
project_name (
str
) – Project name.folder_id (
str
) – Folder id to delete.
- Returns:
Object of delete operation.
- Return type:
- delete_product(project_name, product_id)[source]¶
Delete product.
- Parameters:
project_name (
str
) – Project name.product_id (
str
) – Product id to delete.
- Returns:
Object of delete operation.
- Return type:
- delete_representation(project_name, representation_id)[source]¶
Delete representation.
- Parameters:
project_name (
str
) – Project name.representation_id (
str
) – Representation id to delete.
- Returns:
Object of delete operation.
- Return type:
- delete_task(project_name, task_id)[source]¶
Delete task.
- Parameters:
project_name (
str
) – Project name.task_id (
str
) – Task id to delete.
- Returns:
Object of delete operation.
- Return type:
- delete_version(project_name, version_id)[source]¶
Delete version.
- Parameters:
project_name (
str
) – Project name.version_id (
str
) – Version id to delete.
- Returns:
Object of delete operation.
- Return type:
- extend(operations)[source]¶
Add operations to be processed.
- Parameters:
operations (
List[BaseOperation]
) – Operations that should be processed.
- update_entity(project_name, entity_type, entity_id, update_data, nested_id=None)[source]¶
Fast access to ‘UpdateOperation’.
- Returns:
Object of update operation.
- Return type:
- update_folder(project_name, folder_id, name=None, folder_type=None, parent_id=<object object>, label=<object object>, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=<object object>)[source]¶
Update folder entity on server.
- Do not pass
parent_id
,label
amdthumbnail_id
if you don’t want to change their values. Value
None
would unset their value.
Update of
data
will override existing value on folder entity.- Update of
attrib
does change only passed attributes. If you want to unset value, use
None
.
- Parameters:
project_name (
str
) – Project name.folder_id (
str
) – Folder id.name (
Optional[str]
) – New name.folder_type (
Optional[str]
) – New folder type.parent_id (
Optional[Union[str, None]]
) – New parent folder id.label (
Optional[Union[str, None]]
) – New label.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[Union[str, None]]
) – New thumbnail id.
- Returns:
Object of update operation.
- Return type:
- Do not pass
- update_product(project_name, product_id, name=None, folder_id=None, product_type=None, attrib=None, data=None, tags=None, status=None, active=None)[source]¶
Update product entity on server.
Update of
data
will override existing value on folder entity.- Update of
attrib
does change only passed attributes. If you want to unset value, use
None
.
- Parameters:
project_name (
str
) – Project name.product_id (
str
) – Product id.name (
Optional[str]
) – New product name.folder_id (
Optional[str]
) – New product id.product_type (
Optional[str]
) – New product type.attrib (
Optional[dict[str, Any]]
) – New product attributes.data (
Optional[dict[str, Any]]
) – New product data.tags (
Optional[Iterable[str]]
) – New product tags.status (
Optional[str]
) – New product status.active (
Optional[bool]
) – New product active state.
- Returns:
Object of update operation.
- Return type:
- Update of
- update_representation(project_name, representation_id, name=None, version_id=None, files=None, attrib=None, data=None, tags=None, status=None, active=None)[source]¶
Update representation entity on server.
Update of
data
will override existing value on folder entity.- Update of
attrib
does change only passed attributes. If you want to unset value, use
None
.
- Parameters:
project_name (
str
) – Project name.representation_id (
str
) – Representation id.name (
Optional[str]
) – New name.version_id (
Optional[str]
) – New version id.files (
Optional[list[dict]]
) – New files information.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.
- Returns:
Object of update operation.
- Return type:
- Update of
- update_task(project_name, task_id, name=None, task_type=None, folder_id=None, label=<object object>, assignees=None, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=<object object>)[source]¶
Update task entity on server.
- Do not pass
label
amdthumbnail_id
if you don’t want to change their values. Value
None
would unset their value.
Update of
data
will override existing value on folder entity.- Update of
attrib
does change only passed attributes. If you want to unset value, use
None
.
- Parameters:
project_name (
str
) – Project name.task_id (
str
) – Task id.name (
Optional[str]
) – New name.task_type (
Optional[str]
) – New task type.folder_id (
Optional[str]
) – New folder id.label (
Optional[Union[str, None]]
) – New label.assignees (
Optional[str]
) – New assignees.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[Union[str, None]]
) – New thumbnail id.
- Returns:
Object of update operation.
- Return type:
- Do not pass
- update_version(project_name, version_id, version=None, product_id=None, task_id=<object object>, attrib=None, data=None, tags=None, status=None, active=None, thumbnail_id=<object object>)[source]¶
Update version entity on server.
- Do not pass
task_id
amdthumbnail_id
if you don’t want to change their values. Value
None
would unset their value.
Update of
data
will override existing value on folder entity.- Update of
attrib
does change only passed attributes. If you want to unset value, use
None
.
- Parameters:
project_name (
str
) – Project name.version_id (
str
) – Version id.version (
Optional[int]
) – New version.product_id (
Optional[str]
) – New product id.task_id (
Optional[Union[str, None]]
) – New 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[Union[str, None]]
) – New thumbnail id.
- Returns:
Object of update operation.
- Return type:
- Do not pass
- class UpdateOperation(project_name, entity_type, entity_id, update_data, session)[source]¶
Bases:
AbstractOperation
Operation to update an entity.
- Parameters:
project_name (
str
) – On which project operation will happen.entity_type (
str
) – Type of entity on which change happens. e.g. ‘folder’, ‘representation’ etc.entity_id (
str
) – Identifier of an entity.update_data (
Dict[str, Any]
) – Key -> value changes that will be set in database. If value is set to ‘REMOVED_VALUE’ the key will be removed. Only first level of dictionary is checked (on purpose).
- property con¶
- property entity_id¶
- operation_name = 'update'¶
- property session¶
- to_data()[source]¶
Convert opration to data that can be converted to json or others.
- Returns:
Description of operation.
- Return type:
Dict[str, Any]
- property update_data¶
- new_folder_entity(name, folder_type, parent_id=None, status=None, tags=None, attribs=None, data=None, thumbnail_id=None, entity_id=None)[source]¶
Create skeleton data of folder entity.
- Parameters:
name (
str
) – Is considered as unique identifier of folder in project.folder_type (
str
) – Type of folder.parent_id (
Optional[str]
) – Parent folder id.status (
Optional[str]
) – Product status.tags (
Optional[List[str]]
) – List of tags.attribs (
Optional[Dict[str, Any]]
) – Explicitly set attributes of folder.data (
Optional[Dict[str, Any]]
) – Custom folder data. Empty dictionary is used if not passed.thumbnail_id (
Optional[str]
) – Thumbnail id related to folder.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of folder entity.
- Return type:
Dict[str, Any]
- new_hero_version_entity(version, product_id, task_id=None, thumbnail_id=None, author=None, status=None, tags=None, attribs=None, data=None, entity_id=None)[source]¶
Create skeleton data of hero version entity.
- Parameters:
version (
int
) – Is considered as unique identifier of version under product. Should be same as standard version if there is any.product_id (
str
) – Parent product id.task_id (
Optional[str]
) – Task id under which product was created.thumbnail_id (
Optional[str]
) – Thumbnail related to version.author (
Optional[str]
) – Name of version author.status (
Optional[str]
) – Version status.tags (
Optional[List[str]]
) – List of tags.attribs (
Optional[Dict[str, Any]]
) – Explicitly set attributes of version.data (
Optional[Dict[str, Any]]
) – Version entity data.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of version entity.
- Return type:
Dict[str, Any]
- new_product_entity(name, product_type, folder_id, status=None, tags=None, attribs=None, data=None, entity_id=None)[source]¶
Create skeleton data of product entity.
- Parameters:
name (
str
) – Is considered as unique identifier of product under folder.product_type (
str
) – Product type.folder_id (
str
) – Parent folder id.status (
Optional[str]
) – Product status.tags (
Optional[List[str]]
) – List of tags.attribs (
Optional[Dict[str, Any]]
) – Explicitly set attributes of product.data (
Optional[Dict[str, Any]]
) – product entity data. Empty dictionary is used if not passed.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of product entity.
- Return type:
Dict[str, Any]
- new_representation_entity(name, version_id, files, status=None, tags=None, attribs=None, data=None, entity_id=None)[source]¶
Create skeleton data of representation entity.
- Parameters:
name (
str
) – Representation name considered as unique identifier of representation under version.version_id (
str
) – Parent version id.files (
list[dict[str, str]]
) – List of files in representation.status (
Optional[str]
) – Representation status.tags (
Optional[List[str]]
) – List of tags.attribs (
Optional[Dict[str, Any]]
) – Explicitly set attributes of representation.data (
Optional[Dict[str, Any]]
) – Representation entity data.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of representation entity.
- Return type:
Dict[str, Any]
- new_version_entity(version, product_id, task_id=None, thumbnail_id=None, author=None, status=None, tags=None, attribs=None, data=None, entity_id=None)[source]¶
Create skeleton data of version entity.
- Parameters:
version (
int
) – Is considered as unique identifier of version under product.product_id (
str
) – Parent product id.task_id (
Optional[str]
) – Task id under which product was created.thumbnail_id (
Optional[str]
) – Thumbnail related to version.author (
Optional[str]
) – Name of version author.status (
Optional[str]
) – Version status.tags (
Optional[List[str]]
) – List of tags.attribs (
Optional[Dict[str, Any]]
) – Explicitly set attributes of version.data (
Optional[Dict[str, Any]]
) – Version entity custom data.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of version entity.
- Return type:
Dict[str, Any]
- new_workfile_info(filepath, task_id, status=None, tags=None, attribs=None, description=None, data=None, entity_id=None)[source]¶
Create skeleton data of workfile info entity.
Workfile entity is at this moment used primarily for artist notes.
- Parameters:
filepath (
str
) – Rootless workfile filepath.task_id (
str
) – Task under which was workfile created.status (
Optional[str]
) – Workfile status.tags (
Optional[List[str]]
) – Workfile tags.attribs (
Options[dic[str, Any]]
) – Explicitly set attributes.description (
Optional[str]
) – Workfile description.data (
Optional[Dict[str, Any]]
) – Additional metadata.entity_id (
Optional[str]
) – Predefined id of entity. New id is created if not passed.
- Returns:
Skeleton of workfile info entity.
- Return type:
Dict[str, Any]
- prepare_changes(old_entity, new_entity, entity_type)[source]¶
Prepare changes for entity update.
Notes
- Argument ‘entity_type’ is not used, yet. But there might be
differences in future.
- Parameters:
old_entity (
dict[str, Any]
) – Existing entity.new_entity (
dict[str, Any]
) – New entity.entity_type (
str
) – Entity type. “project”, “folder”, “product” etc.
- Returns:
Changes that have new entity.
- Return type:
dict[str, Any]