-
Notifications
You must be signed in to change notification settings - Fork 67
(YN-0075) Publish shot attributes on demand with setting #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakubjezek001
wants to merge
9
commits into
develop
Choose a base branch
from
enhancement/YN-0075_publish_shot_attributes_on_demand_with_setting
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−35
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
85c5fac
no need to specify hosts in plugin where only `shot` product type is
jakubjezek001 6c768d3
Add CollectHierarchy publish plugin settings
jakubjezek001 82cb180
Add option to ignore shot attributes update
jakubjezek001 39e1233
adding todo
jakubjezek001 8fcd6c0
Collect existing folder entities for shots
jakubjezek001 ea598a3
Add missing blank line in publish_plugins.py
jakubjezek001 4d47cb7
Refactor: Simplify CollectHierarchy logic
jakubjezek001 ec1e118
Collect only 'path' field when checking hierarchy
jakubjezek001 94a8ddb
Debug log instance folder path and attributes update state
jakubjezek001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| import pyblish.api | ||
| from ayon_core.lib import BoolDef | ||
| import ayon_api | ||
| from ayon_core.pipeline import publish | ||
|
|
||
|
|
||
| class CollectHierarchy(pyblish.api.ContextPlugin): | ||
| class CollectHierarchy( | ||
| pyblish.api.ContextPlugin, | ||
| publish.AYONPyblishPluginMixin, | ||
| ): | ||
| """Collecting hierarchy from `parents`. | ||
|
|
||
| present in `clip` family instances coming from the request json data file | ||
|
|
@@ -13,20 +19,40 @@ class CollectHierarchy(pyblish.api.ContextPlugin): | |
|
|
||
| label = "Collect Hierarchy" | ||
| order = pyblish.api.CollectorOrder - 0.076 | ||
| hosts = ["resolve", "hiero", "flame", "traypublisher"] | ||
| settings_category = "core" | ||
|
|
||
| def process(self, context): | ||
| project_name = context.data["projectName"] | ||
| final_context = { | ||
| project_name: { | ||
| "entity_type": "project", | ||
| "children": {} | ||
| }, | ||
| } | ||
| temp_context = {} | ||
| for instance in context: | ||
| self.log.debug("Processing instance: `{}` ...".format(instance)) | ||
| ignore_shot_attributes_on_update = False | ||
|
|
||
| @classmethod | ||
| def get_attr_defs_for_context(cls, create_context): | ||
| return [ | ||
| BoolDef( | ||
| "ignore_shot_attributes_on_update", | ||
| label="Ignore shot attributes on update", | ||
| default=cls.ignore_shot_attributes_on_update | ||
| ) | ||
| ] | ||
|
|
||
| @classmethod | ||
| def apply_settings(cls, project_settings): | ||
| cls.ignore_shot_attributes_on_update = ( | ||
| project_settings | ||
| ["core"] | ||
| ["CollectHierarchy"] | ||
| ["ignore_shot_attributes_on_update"] | ||
| ) | ||
|
|
||
| def _get_shot_instances(self, context): | ||
| """Get shot instances from context. | ||
|
|
||
| Args: | ||
| context (pyblish.api.Context): Context is a list of instances. | ||
|
|
||
| Returns: | ||
| list[pyblish.api.Instance]: A list of shot instances. | ||
| """ | ||
| shot_instances = [] | ||
| for instance in context: | ||
| # shot data dict | ||
| product_type = instance.data["productType"] | ||
| families = instance.data["families"] | ||
|
|
@@ -41,6 +67,67 @@ def process(self, context): | |
| self.log.debug("Skipping not a shot from hero track") | ||
| continue | ||
|
|
||
| shot_instances.append(instance) | ||
|
|
||
| return shot_instances | ||
|
|
||
| def get_existing_folder_entities(self, project_name, shot_instances): | ||
| """Get existing folder entities for given shot instances. | ||
|
|
||
| Args: | ||
| project_name (str): The name of the project. | ||
| shot_instances (list[pyblish.api.Instance]): A list of shot | ||
| instances. | ||
|
|
||
| Returns: | ||
| dict[str, dict]: A dictionary mapping folder paths to existing | ||
| folder entities. | ||
| """ | ||
| # first we need to get all folder paths from shot instances | ||
| folder_paths = { | ||
| instance.data["folderPath"] | ||
| for instance in shot_instances | ||
| } | ||
| # then we get all existing folder entities with one request | ||
| existing_entities = { | ||
| folder_entity["path"]: folder_entity | ||
| for folder_entity in ayon_api.get_folders( | ||
| project_name, folder_paths=folder_paths, fields={"path"}) | ||
| } | ||
| for folder_path in folder_paths: | ||
| # add None value to non-existing folder entities | ||
| existing_entities.setdefault(folder_path, None) | ||
|
|
||
| return existing_entities | ||
|
|
||
| def process(self, context): | ||
| # get only shot instances from context | ||
| shot_instances = self._get_shot_instances(context) | ||
|
|
||
| if not shot_instances: | ||
| return | ||
|
|
||
| # get user input | ||
| values = self.get_attr_values_from_data(context.data) | ||
| ignore_shot_attributes_on_update = values.get( | ||
| "ignore_shot_attributes_on_update", None) | ||
|
|
||
| project_name = context.data["projectName"] | ||
| final_context = { | ||
| project_name: { | ||
| "entity_type": "project", | ||
| "children": {} | ||
| }, | ||
| } | ||
| temp_context = {} | ||
| existing_entities = self.get_existing_folder_entities( | ||
| project_name, shot_instances) | ||
|
|
||
| for instance in shot_instances: | ||
| folder_path = instance.data["folderPath"] | ||
| self.log.debug( | ||
| f"Processing instance: `{folder_path} {instance}` ...") | ||
|
|
||
| shot_data = { | ||
| "entity_type": "folder", | ||
| # WARNING unless overwritten, default folder type is hardcoded | ||
|
|
@@ -51,32 +138,43 @@ def process(self, context): | |
| } | ||
|
|
||
| shot_data["attributes"] = {} | ||
| SHOT_ATTRS = ( | ||
| "handleStart", | ||
| "handleEnd", | ||
| "frameStart", | ||
| "frameEnd", | ||
| "clipIn", | ||
| "clipOut", | ||
| "fps", | ||
| "resolutionWidth", | ||
| "resolutionHeight", | ||
| "pixelAspect", | ||
| ) | ||
| for shot_attr in SHOT_ATTRS: | ||
| attr_value = instance.data.get(shot_attr) | ||
| if attr_value is None: | ||
| # Shot attribute might not be defined (e.g. CSV ingest) | ||
| # we need to check if the shot entity already exists | ||
| # and if not the attributes needs to be added in case the option | ||
| # is disabled by settings | ||
| if ( | ||
| existing_entities.get(folder_path) | ||
| and not ignore_shot_attributes_on_update | ||
| ): | ||
| SHOT_ATTRS = ( | ||
| "handleStart", | ||
| "handleEnd", | ||
| "frameStart", | ||
| "frameEnd", | ||
| "clipIn", | ||
| "clipOut", | ||
| "fps", | ||
| "resolutionWidth", | ||
| "resolutionHeight", | ||
| "pixelAspect", | ||
| ) | ||
|
Comment on lines
+148
to
+159
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this can be at the top of the files as constant. |
||
| for shot_attr in SHOT_ATTRS: | ||
| attr_value = instance.data.get(shot_attr) | ||
| if attr_value is None: | ||
| # Shot attribute might not be defined (e.g. CSV ingest) | ||
| self.log.debug( | ||
| "%s shot attribute is not defined for instance.", | ||
| shot_attr | ||
| ) | ||
| continue | ||
|
|
||
| shot_data["attributes"][shot_attr] = attr_value | ||
| else: | ||
| self.log.debug( | ||
| "%s shot attribute is not defined for instance.", | ||
| shot_attr | ||
| "Shot attributes will not be updated." | ||
| ) | ||
| continue | ||
|
|
||
| shot_data["attributes"][shot_attr] = attr_value | ||
|
|
||
| # Split by '/' for AYON where asset is a path | ||
| name = instance.data["folderPath"].split("/")[-1] | ||
| name = folder_path.split("/")[-1] | ||
| actual = {name: shot_data} | ||
|
|
||
| for parent in reversed(instance.data["parents"]): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.