mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
113 lines
3.7 KiB
Python
113 lines
3.7 KiB
Python
"""
|
|
Requires:
|
|
session -> AVALON_PROJECT
|
|
context -> anatomy (pypeapp.Anatomy)
|
|
instance -> subset
|
|
instance -> asset
|
|
instance -> family
|
|
|
|
Provides:
|
|
instance -> template
|
|
instance -> assumedTemplateData
|
|
instance -> assumedDestination
|
|
"""
|
|
|
|
import os
|
|
|
|
from avalon import io, api
|
|
import pyblish.api
|
|
|
|
|
|
class CollectTemplates(pyblish.api.InstancePlugin):
|
|
"""Fill templates with data needed for publish"""
|
|
|
|
order = pyblish.api.CollectorOrder + 0.1
|
|
label = "Collect and fill Templates"
|
|
hosts = ["maya", "nuke", "standalonepublisher"]
|
|
|
|
def process(self, instance):
|
|
# get all the stuff from the database
|
|
subset_name = instance.data["subset"]
|
|
asset_name = instance.data["asset"]
|
|
project_name = api.Session["AVALON_PROJECT"]
|
|
|
|
project = io.find_one(
|
|
{
|
|
"type": "project",
|
|
"name": project_name
|
|
},
|
|
projection={"config": True, "data": True}
|
|
)
|
|
|
|
template = project["config"]["template"]["publish"]
|
|
anatomy = instance.context.data['anatomy']
|
|
|
|
asset = io.find_one({
|
|
"type": "asset",
|
|
"name": asset_name,
|
|
"parent": project["_id"]
|
|
})
|
|
|
|
assert asset, ("No asset found by the name '{}' "
|
|
"in project '{}'".format(asset_name, project_name))
|
|
silo = asset.get('silo')
|
|
|
|
subset = io.find_one({
|
|
"type": "subset",
|
|
"name": subset_name,
|
|
"parent": asset["_id"]
|
|
})
|
|
|
|
# assume there is no version yet, we start at `1`
|
|
version = None
|
|
version_number = 1
|
|
if subset is not None:
|
|
version = io.find_one(
|
|
{
|
|
"type": "version",
|
|
"parent": subset["_id"]
|
|
},
|
|
sort=[("name", -1)]
|
|
)
|
|
|
|
# if there is a subset there ought to be version
|
|
if version is not None:
|
|
version_number += int(version["name"])
|
|
|
|
hierarchy = asset['data']['parents']
|
|
if hierarchy:
|
|
# hierarchy = os.path.sep.join(hierarchy)
|
|
hierarchy = os.path.join(*hierarchy)
|
|
|
|
template_data = {"root": api.Session["AVALON_PROJECTS"],
|
|
"project": {"name": project_name,
|
|
"code": project['data']['code']},
|
|
"silo": silo,
|
|
"family": instance.data['family'],
|
|
"asset": asset_name,
|
|
"subset": subset_name,
|
|
"version": version_number,
|
|
"hierarchy": hierarchy.replace("\\", "/"),
|
|
"representation": "TEMP")}
|
|
|
|
resolution_width = instance.data.get("resolutionWidth")
|
|
resolution_height = instance.data.get("resolutionHeight")
|
|
fps = instance.data.get("fps")
|
|
|
|
if resolution_width:
|
|
template_data["resolution_width"] = resolution_width
|
|
if resolution_width:
|
|
template_data["resolution_height"] = resolution_height
|
|
if resolution_width:
|
|
template_data["fps"] = fps
|
|
|
|
instance.data["template"] = template
|
|
instance.data["assumedTemplateData"] = template_data
|
|
|
|
# We take the parent folder of representation 'filepath'
|
|
instance.data["assumedDestination"] = os.path.dirname(
|
|
(anatomy.format(template_data))["publish"]["path"]
|
|
)
|
|
self.log.info("Assumed Destination has been created...")
|
|
self.log.debug("__ assumedTemplateData: `{}`".format(instance.data["assumedTemplateData"]))
|
|
self.log.debug("__ template: `{}`".format(instance.data["template"]))
|