Merge pull request #4093 from pypeclub/enhancement/online-family

Online family for Tray Publisher
This commit is contained in:
Ondřej Samohel 2022-11-21 12:06:55 +01:00 committed by GitHub
commit e8ce60fd2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 180 additions and 8 deletions

View file

@ -389,10 +389,11 @@ def get_subset_by_name(project_name, subset_name, asset_id, fields=None):
returned if 'None' is passed.
Returns:
None: If subset with specified filters was not found.
Dict: Subset document which can be reduced to specified 'fields'.
"""
Union[None, Dict[str, Any]]: None if subset with specified filters was
not found or dict subset document which can be reduced to
specified 'fields'.
"""
if not subset_name:
return None

View file

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
"""Creator of online files.
Online file retain their original name and use it as subset name. To
avoid conflicts, this creator checks if subset with this name already
exists under selected asset.
"""
from pathlib import Path
from openpype.client import get_subset_by_name, get_asset_by_name
from openpype.lib.attribute_definitions import FileDef
from openpype.pipeline import (
CreatedInstance,
CreatorError
)
from openpype.hosts.traypublisher.api.plugin import TrayPublishCreator
class OnlineCreator(TrayPublishCreator):
"""Creates instance from file and retains its original name."""
identifier = "io.openpype.creators.traypublisher.online"
label = "Online"
family = "online"
description = "Publish file retaining its original file name"
extensions = [".mov", ".mp4", ".mxf", ".m4v", ".mpg"]
def get_detail_description(self):
return """# Create file retaining its original file name.
This will publish files using template helping to retain original
file name and that file name is used as subset name.
Bz default it tries to guard against multiple publishes of the same
file."""
def get_icon(self):
return "fa.file"
def create(self, subset_name, instance_data, pre_create_data):
repr_file = pre_create_data.get("representation_file")
if not repr_file:
raise CreatorError("No files specified")
files = repr_file.get("filenames")
if not files:
# this should never happen
raise CreatorError("Missing files from representation")
origin_basename = Path(files[0]).stem
asset = get_asset_by_name(
self.project_name, instance_data["asset"], fields=["_id"])
if get_subset_by_name(
self.project_name, origin_basename, asset["_id"],
fields=["_id"]):
raise CreatorError(f"subset with {origin_basename} already "
"exists in selected asset")
instance_data["originalBasename"] = origin_basename
subset_name = origin_basename
instance_data["creator_attributes"] = {
"path": (Path(repr_file["directory"]) / files[0]).as_posix()
}
# Create new instance
new_instance = CreatedInstance(self.family, subset_name,
instance_data, self)
self._store_new_instance(new_instance)
def get_pre_create_attr_defs(self):
return [
FileDef(
"representation_file",
folders=False,
extensions=self.extensions,
allow_sequences=False,
single_item=True,
label="Representation",
)
]
def get_subset_name(
self,
variant,
task_name,
asset_doc,
project_name,
host_name=None,
instance=None
):
if instance is None:
return "{originalBasename}"
return instance.data["subset"]

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
import pyblish.api
from pathlib import Path
class CollectOnlineFile(pyblish.api.InstancePlugin):
"""Collect online file and retain its file name."""
label = "Collect Online File"
order = pyblish.api.CollectorOrder
families = ["online"]
hosts = ["traypublisher"]
def process(self, instance):
file = Path(instance.data["creator_attributes"]["path"])
instance.data["representations"].append(
{
"name": file.suffix.lstrip("."),
"ext": file.suffix.lstrip("."),
"files": file.name,
"stagingDir": file.parent.as_posix()
}
)

View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
import pyblish.api
from openpype.pipeline.publish import (
ValidateContentsOrder,
PublishValidationError,
OptionalPyblishPluginMixin,
)
from openpype.client import get_subset_by_name
class ValidateOnlineFile(OptionalPyblishPluginMixin,
pyblish.api.InstancePlugin):
"""Validate that subset doesn't exist yet."""
label = "Validate Existing Online Files"
hosts = ["traypublisher"]
families = ["online"]
order = ValidateContentsOrder
optional = True
def process(self, instance):
project_name = instance.context.data["projectName"]
asset_id = instance.data["assetEntity"]["_id"]
subset = get_subset_by_name(
project_name, instance.data["subset"], asset_id)
if subset:
raise PublishValidationError(
"Subset to be published already exists.",
title=self.label
)

View file

@ -393,8 +393,9 @@ class BaseCreator:
asset_doc(dict): Asset document for which subset is created.
project_name(str): Project name.
host_name(str): Which host creates subset.
instance(str|None): Object of 'CreatedInstance' for which is
subset name updated. Passed only on subset name update.
instance(CreatedInstance|None): Object of 'CreatedInstance' for
which is subset name updated. Passed only on subset name
update.
"""
dynamic_data = self.get_dynamic_data(

View file

@ -129,7 +129,8 @@ class IntegrateAsset(pyblish.api.InstancePlugin):
"mvUsd",
"mvUsdComposition",
"mvUsdOverride",
"simpleUnrealTexture"
"simpleUnrealTexture",
"online"
]
default_template_name = "publish"

View file

@ -48,10 +48,16 @@
"file": "{originalBasename}_{@version}.{ext}",
"path": "{@folder}/{@file}"
},
"online": {
"folder": "{root[work]}/{project[name]}/{hierarchy}/{asset}/publish/{family}/{subset}/{@version}",
"file": "{originalBasename}<.{@frame}><_{udim}>.{ext}",
"path": "{@folder}/{@file}"
},
"__dynamic_keys_labels__": {
"maya2unreal": "Maya to Unreal",
"simpleUnrealTextureHero": "Simple Unreal Texture - Hero",
"simpleUnrealTexture": "Simple Unreal Texture"
"simpleUnrealTexture": "Simple Unreal Texture",
"online": "online"
}
}
}

View file

@ -484,7 +484,19 @@
]
},
"publish": {
"template_name_profiles": [],
"template_name_profiles": [
{
"families": [
"online"
],
"hosts": [
"traypublisher"
],
"task_types": [],
"task_names": [],
"template_name": "online"
}
],
"hero_template_name_profiles": []
}
},