Skip to content

Commit

Permalink
added new function to calculate representation delivery data
Browse files Browse the repository at this point in the history
  • Loading branch information
iLLiCiTiT committed Oct 15, 2024
1 parent 360a7d2 commit f1a1e77
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 13 deletions.
80 changes: 79 additions & 1 deletion client/ayon_core/pipeline/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import copy
import shutil
import glob
import clique
import collections
from typing import List, Dict, Any, Iterable

import clique
import ayon_api

from ayon_core.lib import create_hard_link

from .anatomy import Anatomy
from .template_data import (
get_general_template_data,
get_folder_template_data,
get_task_template_data,
)


def _copy_file(src_path, dst_path):
"""Hardlink file if possible(to save space), copy if not.
Expand Down Expand Up @@ -327,3 +337,71 @@ def hash_path_exist(myPath):
uploaded += 1

return report_items, uploaded


def _merge_data(data, new_data):
queue = collections.deque()
queue.append((data, new_data))
while queue:
q_data, q_new_data = queue.popleft()
for key, value in q_new_data.items():
if key in q_data and isinstance(value, dict):
queue.append((q_data[key], value))
continue
q_data[key] = value


def get_representations_delivery_template_data(
project_name: str,
representation_ids: Iterable[str],
) -> Dict[str, Dict[str, Any]]:
representation_ids = set(representation_ids)

output = {
repre_id: {}
for repre_id in representation_ids
}
if not representation_ids:
return output

project_entity = ayon_api.get_project(project_name)

general_template_data = get_general_template_data()

repres_hierarchy = ayon_api.get_representations_hierarchy(
project_name,
representation_ids,
project_fields=set(),
folder_fields={"path", "folderType"},
task_fields={"name", "taskType"},
product_fields={"name", "productType"},
version_fields={"version", "productId"},
representation_fields=None,
)
for repre_id, repre_hierarchy in repres_hierarchy.items():
repre_entity = repre_hierarchy.representation
if repre_entity is None:
continue

template_data = repre_entity["context"]
template_data.update(copy.deepcopy(general_template_data))
template_data.update(get_folder_template_data(
repre_hierarchy.folder, project_name
))
if repre_hierarchy.task:
template_data.update(get_task_template_data(
project_entity, repre_hierarchy.task
))

product_entity = repre_hierarchy.product
version_entity = repre_hierarchy.version
template_data.update({
"product": {
"name": product_entity["name"],
"type": product_entity["productType"],
},
"version": version_entity["version"],
})
_merge_data(template_data, repre_entity["context"])
output[repre_id] = template_data
return output
33 changes: 21 additions & 12 deletions client/ayon_core/plugins/load/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,29 @@ def deliver(self):
format_dict = get_format_dict(self.anatomy, self.root_line_edit.text())
renumber_frame = self.renumber_frame.isChecked()
frame_offset = self.first_frame_start.value()
filtered_repres = []
repre_ids = set()
for repre in self._representations:
if repre["name"] not in selected_repres:
continue
if repre["name"] in selected_repres:
filtered_repres.append(repre)
repre_ids.add(repre["id"])

template_data_by_repre_id = get_representations_template_data(
self.anatomy.project_name, repre_ids
)
for repre in filtered_repres:
repre_path = get_representation_path_with_anatomy(
repre, self.anatomy
)

anatomy_data = copy.deepcopy(repre["context"])
new_report_items = check_destination_path(repre["id"],
self.anatomy,
anatomy_data,
datetime_data,
template_name)
template_data = template_data_by_repre_id[repre["id"]]
new_report_items = check_destination_path(
repre["id"],
self.anatomy,
template_data,
datetime_data,
template_name
)

report_items.update(new_report_items)
if new_report_items:
Expand All @@ -224,7 +233,7 @@ def deliver(self):
repre,
self.anatomy,
template_name,
anatomy_data,
template_data,
format_dict,
report_items,
self.log
Expand Down Expand Up @@ -267,17 +276,17 @@ def deliver(self):

if frame is not None:
if repre["context"].get("frame"):
anatomy_data["frame"] = frame
template_data["frame"] = frame
elif repre["context"].get("udim"):
anatomy_data["udim"] = frame
template_data["udim"] = frame
else:
# Fallback
self.log.warning(
"Representation context has no frame or udim"
" data. Supplying sequence frame to '{frame}'"
" formatting data."
)
anatomy_data["frame"] = frame
template_data["frame"] = frame
new_report_items, uploaded = deliver_single_file(*args)
report_items.update(new_report_items)
self._update_progress(uploaded)
Expand Down

0 comments on commit f1a1e77

Please sign in to comment.