Merge branch 'develop' into bugfix/PYPE-428-dazzle-feedback-publish-errors

This commit is contained in:
jezschaj 2019-07-17 11:37:55 +02:00
commit 559101217d
19 changed files with 326 additions and 203 deletions

View file

@ -12,6 +12,5 @@ class CollectTemplates(pyblish.api.ContextPlugin):
label = "Collect Templates"
def process(self, context):
# pype.load_data_from_templates()
context.data['anatomy'] = Anatomy()
self.log.info("Anatomy templates collected...")

View file

@ -44,10 +44,7 @@ class PremierePro(api.Action):
env = acre.merge(env, current_env=dict(os.environ))
if not env.get('AVALON_WORKDIR', None):
pype.load_data_from_templates()
os.environ["AVALON_WORKDIR"] = pype.get_workdir_template(
pype.Anatomy)
pype.reset_data_from_templates()
os.environ["AVALON_WORKDIR"] = pype.get_workdir_template()
env.update(dict(os.environ))

View file

@ -9,7 +9,7 @@ class ModelLoader(pype.maya.plugin.ReferenceLoader):
"""Load the model"""
families = ["model"]
representations = ["ma"]
representations = ["ma", "abc"]
tool_names = ["loader"]
label = "Reference Model"
@ -25,14 +25,18 @@ class ModelLoader(pype.maya.plugin.ReferenceLoader):
with maya.maintained_selection():
groupName = "{}:{}".format(namespace, name)
cmds.loadPlugin("AbcImport.mll", quiet=True)
nodes = cmds.file(self.fname,
namespace=namespace,
sharedReferenceFile=False,
groupReference=True,
groupName=groupName,
groupName="{}:{}".format(namespace, name),
reference=True,
returnNewNodes=True)
nodes.pop(0)
namespace = cmds.referenceQuery(nodes[0], namespace=True)
nodes.pop(1)
roots = set()
for node in nodes:
try:
@ -54,9 +58,9 @@ class ModelLoader(pype.maya.plugin.ReferenceLoader):
cmds.setAttr(groupName + ".outlinerColor",
c[0], c[1], c[2])
self[:] = nodes
self[:] = nodes
return nodes
return nodes
def switch(self, container, representation):
self.update(container, representation)
@ -161,59 +165,59 @@ class GpuCacheLoader(api.Loader):
pass
class AbcModelLoader(pype.maya.plugin.ReferenceLoader):
"""Specific loader of Alembic for the studio.animation family"""
families = ["model"]
representations = ["abc"]
tool_names = ["loader"]
label = "Reference Model"
order = -10
icon = "code-fork"
color = "orange"
def process_reference(self, context, name, namespace, data):
import maya.cmds as cmds
groupName = "{}:{}".format(namespace, name)
cmds.loadPlugin("AbcImport.mll", quiet=True)
nodes = cmds.file(self.fname,
namespace=namespace,
sharedReferenceFile=False,
groupReference=True,
groupName="{}:{}".format(namespace, name),
reference=True,
returnNewNodes=True)
namespace = cmds.referenceQuery(nodes[0], namespace=True)
nodes.pop(0)
roots = set()
for node in nodes:
try:
roots.add(cmds.ls(node, long=True)[0].split('|')[2])
except:
pass
cmds.parent(roots, world=True)
cmds.makeIdentity(groupName, apply=False, rotate=True,
translate=True, scale=True)
cmds.parent(roots, groupName)
nodes.append(groupName)
presets = config.get_presets(project=os.environ['AVALON_PROJECT'])
colors = presets['plugins']['maya']['load']['colors']
c = colors.get('model')
if c is not None:
cmds.setAttr(groupName + ".useOutlinerColor", 1)
cmds.setAttr(groupName + ".outlinerColor",
c[0], c[1], c[2])
self[:] = nodes
return roots
def switch(self, container, representation):
self.update(container, representation)
# class AbcModelLoader(pype.maya.plugin.ReferenceLoader):
# """Specific loader of Alembic for the studio.animation family"""
#
# families = ["model"]
# representations = ["abc"]
# tool_names = ["loader"]
#
# label = "Reference Model"
# order = -10
# icon = "code-fork"
# color = "orange"
#
# def process_reference(self, context, name, namespace, data):
#
# import maya.cmds as cmds
#
# groupName = "{}:{}".format(namespace, name)
# cmds.loadPlugin("AbcImport.mll", quiet=True)
# nodes = cmds.file(self.fname,
# namespace=namespace,
# sharedReferenceFile=False,
# groupReference=True,
# groupName="{}:{}".format(namespace, name),
# reference=True,
# returnNewNodes=True)
#
# namespace = cmds.referenceQuery(nodes[0], namespace=True)
#
# nodes.pop(0)
# roots = set()
# for node in nodes:
# try:
# roots.add(cmds.ls(node, long=True)[0].split('|')[2])
# except:
# pass
# cmds.parent(roots, world=True)
# cmds.makeIdentity(groupName, apply=False, rotate=True,
# translate=True, scale=True)
# cmds.parent(roots, groupName)
#
# nodes.append(groupName)
#
# presets = config.get_presets(project=os.environ['AVALON_PROJECT'])
# colors = presets['plugins']['maya']['load']['colors']
# c = colors.get('model')
# if c is not None:
# cmds.setAttr(groupName + ".useOutlinerColor", 1)
# cmds.setAttr(groupName + ".outlinerColor",
# c[0], c[1], c[2])
#
# self[:] = nodes
#
# return nodes
#
# def switch(self, container, representation):
# self.update(container, representation)

View file

@ -0,0 +1,95 @@
import pymel.core as pm
import pyblish.api
import pype.api
class ValidateAttributes(pyblish.api.ContextPlugin):
"""Ensure attributes are consistent.
Attributes to validate and their values comes from the
"maya/attributes.json" preset, which needs this structure:
{
"family": {
"node_name.attribute_name": attribute_value
}
}
"""
order = pype.api.ValidateContentsOrder
label = "Attributes"
hosts = ["maya"]
actions = [pype.api.RepairContextAction]
def process(self, context):
# Check for preset existence.
if not context.data["presets"]["maya"].get("attributes"):
return
invalid = self.get_invalid(context, compute=True)
if invalid:
raise RuntimeError(
"Found attributes with invalid values: {}".format(invalid)
)
@classmethod
def get_invalid(cls, context, compute=False):
invalid = context.data.get("invalid_attributes", [])
if compute:
invalid = cls.get_invalid_attributes(context)
return invalid
@classmethod
def get_invalid_attributes(cls, context):
presets = context.data["presets"]["maya"]["attributes"]
invalid_attributes = []
for instance in context:
# Filter publisable instances.
if not instance.data["publish"]:
continue
# Filter families.
families = [instance.data["family"]]
families += instance.data.get("families", [])
families = list(set(families) & set(presets.keys()))
if not families:
continue
# Get all attributes to validate.
attributes = {}
for family in families:
for preset in presets[family]:
[node_name, attribute_name] = preset.split(".")
attributes.update(
{node_name: {attribute_name: presets[family][preset]}}
)
# Get invalid attributes.
nodes = [pm.PyNode(x) for x in instance]
for node in nodes:
name = node.name(stripNamespace=True)
if name not in attributes.keys():
continue
presets_to_validate = attributes[name]
for attribute in node.listAttr():
if attribute.attrName() in presets_to_validate:
expected = presets_to_validate[attribute.attrName()]
if attribute.get() != expected:
invalid_attributes.append(
{
"attribute": attribute,
"expected": expected,
"current": attribute.get()
}
)
context.data["invalid_attributes"] = invalid_attributes
return invalid_attributes
@classmethod
def repair(cls, instance):
invalid = cls.get_invalid(instance)
for data in invalid:
data["attribute"].set(data["expected"])

View file

@ -1,5 +1,4 @@
import pyblish.api
import pype.api as pype
class CollectCurrentFile(pyblish.api.ContextPlugin):
"""Inject the current working file into context"""
@ -8,10 +7,7 @@ class CollectCurrentFile(pyblish.api.ContextPlugin):
def process(self, context):
"""Todo, inject the current working file"""
project = context.data('activeProject')
context.data["currentFile"] = path = project.path()
context.data["version"] = pype.get_version_from_path(path)
self.log.info("currentFile: {}".format(context.data["currentFile"]))
self.log.info("version: {}".format(context.data["version"]))

View file

@ -0,0 +1,15 @@
import pyblish.api
import pype.api as pype
class CollectWorkfileVersion(pyblish.api.ContextPlugin):
"""Inject the current working file version into context"""
order = pyblish.api.CollectorOrder - 0.1
label = "Collect workfile version"
def process(self, context):
project = context.data('activeProject')
path = project.path()
context.data["version"] = pype.get_version_from_path(path)
self.log.info("version: {}".format(context.data["version"]))

View file

@ -0,0 +1,74 @@
import pyblish
from avalon import io
from pype.action import get_errored_instances_from_context
import pype.api as pype
@pyblish.api.log
class RepairNukestudioVersionUp(pyblish.api.Action):
label = "Version Up Workfile"
on = "failed"
icon = "wrench"
def process(self, context, plugin):
errored_instances = get_errored_instances_from_context(context)
# Apply pyblish logic to get the instances for the plug-in
instances = pyblish.api.instances_by_plugin(errored_instances, plugin)
if instances:
project = context.data["activeProject"]
path = context.data.get("currentFile")
new_path = pype.version_up(path)
if project:
project.saveAs(new_path)
self.log.info("Project workfile version was fixed")
class ValidateVersion(pyblish.api.InstancePlugin):
"""Validate clip's versions.
"""
order = pyblish.api.ValidatorOrder
families = ["plate"]
label = "Validate Version"
actions = [RepairNukestudioVersionUp]
hosts = ["nukestudio"]
def process(self, instance):
version = int(instance.data.get("version", 0))
asset_name = instance.data.get("asset", None)
subset_name = instance.data.get("subset", None)
assert version, "The file is missing version string! example: filename_v001.hrox `{}`"
self.log.debug("Collected version: `{0}`".format(version))
found_v = 0
try:
io.install()
project = io.find_one({"type": "project"})
asset = io.find_one({"type": "asset",
"name": asset_name,
"parent": project["_id"]})
subset = io.find_one({"type": "subset",
"parent": asset["_id"],
"name": subset_name})
version_db = io.find_one({
'type': 'version',
'parent': subset["_id"],
'name': version
}) or {}
found_v = version_db.get("name", 0)
self.log.debug("Found version: `{0}`".format(found_v))
except Exception as e:
self.log.debug("Problem to get data from database for asset `{0}` subset `{1}`. Error: `{2}`".format(asset_name, subset_name, e))
assert (found_v != version), "Version must not be the same as in database `{0}`, Versions file: `{1}`, db: `{2}`".format(asset_name, version, found_v)

View file

@ -0,0 +1,23 @@
from pyblish import api
import pype.api as pype
class VersionUpWorkfile(api.ContextPlugin):
"""Save as new workfile version"""
order = api.IntegratorOrder + 10.1
label = "Version-up Workfile"
hosts = ["nukestudio"]
optional = True
active = True
def process(self, context):
project = context.data["activeProject"]
path = context.data.get("currentFile")
new_path = pype.version_up(path)
if project:
project.saveAs(new_path)
self.log.info("Project workfile was versioned up")