From e75c64114670f734cb049979d1b7cea041d0c746 Mon Sep 17 00:00:00 2001 From: aardschok Date: Mon, 26 Jun 2017 11:15:07 +0200 Subject: [PATCH] Integrated context repair class --- colorbleed/action.py | 46 +++++++++++++++++++ colorbleed/api.py | 14 +----- colorbleed/maya/lib.py | 2 +- colorbleed/plugins/maya/load/load_model.py | 1 + .../maya/publish/_validate_units_angular.py | 20 -------- .../maya/publish/_validate_units_fps.py | 28 ----------- .../maya/publish/_validate_units_linear.py | 20 -------- .../maya/publish/collect_current_file.py | 4 +- .../maya/publish/validate_maya_units.py | 26 ++++++++--- .../maya/publish/validate_rig_contents.py | 15 +++--- 10 files changed, 78 insertions(+), 98 deletions(-) delete mode 100644 colorbleed/plugins/maya/publish/_validate_units_angular.py delete mode 100644 colorbleed/plugins/maya/publish/_validate_units_fps.py delete mode 100644 colorbleed/plugins/maya/publish/_validate_units_linear.py diff --git a/colorbleed/action.py b/colorbleed/action.py index aad054044d..69562b1ef0 100644 --- a/colorbleed/action.py +++ b/colorbleed/action.py @@ -20,6 +20,27 @@ def get_errored_instances_from_context(context): return instances +def get_errored_plugins_from_data(context): + """Get all failed validation plugins + + Args: + context (object): + + Returns: + list of plugins which failed during validation + + """ + + plugins = list() + results = context.data.get("results", []) + for result in results: + if result["success"] == True: + continue + plugins.append(result["plugin"]) + + return plugins + + class RepairAction(pyblish.api.Action): """Repairs the action @@ -47,6 +68,31 @@ class RepairAction(pyblish.api.Action): plugin.repair(instance) +class RepairContextAction(pyblish.api.Action): + """Repairs the action + + To retrieve the invalid nodes this assumes a static `repair(instance)` + method is available on the plugin. + + """ + label = "Repair Context" + on = "failed" # This action is only available on a failed plug-in + + def process(self, context, plugin): + + if not hasattr(plugin, "repair"): + raise RuntimeError("Plug-in does not have repair method.") + + # Get the errored instances + self.log.info("Finding failed instances..") + errored_plugins = get_errored_plugins_from_data(context) + + # Apply pyblish.logic to get the instances for the plug-in + if plugin in errored_plugins: + self.log.info("Attempting fix ...") + plugin.repair() + + class SelectInvalidAction(pyblish.api.Action): """Select invalid nodes in Maya when plug-in failed. diff --git a/colorbleed/api.py b/colorbleed/api.py index 21ac9ba409..9de699fa62 100644 --- a/colorbleed/api.py +++ b/colorbleed/api.py @@ -14,20 +14,10 @@ from .plugin import ( from .action import ( SelectInvalidAction, GenerateUUIDsOnInvalidAction, - RepairAction + RepairAction, + RepairContextAction ) - -def merge(*args): - """Helper to merge OrderedDict instances""" - data = OrderedDict() - for arg in args: - for key, value in arg.items(): - data.pop(key, None) - data[key] = value - return data - - all = [ "Extractor", "ValidatePipelineOrder", diff --git a/colorbleed/maya/lib.py b/colorbleed/maya/lib.py index aa5345166c..6d4c9a272c 100644 --- a/colorbleed/maya/lib.py +++ b/colorbleed/maya/lib.py @@ -241,4 +241,4 @@ def collect_animation_data(): def get_current_renderlayer(): - return cmds.editRenderLayerGlobals(query=True, currentRenderLayer=True) \ No newline at end of file + return cmds.editRenderLayerGlobals(query=True, currentRenderLayer=True) diff --git a/colorbleed/plugins/maya/load/load_model.py b/colorbleed/plugins/maya/load/load_model.py index 65dd3e2fd0..bfb0decaca 100644 --- a/colorbleed/plugins/maya/load/load_model.py +++ b/colorbleed/plugins/maya/load/load_model.py @@ -1,4 +1,5 @@ from maya import cmds + from avalon import api diff --git a/colorbleed/plugins/maya/publish/_validate_units_angular.py b/colorbleed/plugins/maya/publish/_validate_units_angular.py deleted file mode 100644 index 6ac560ee60..0000000000 --- a/colorbleed/plugins/maya/publish/_validate_units_angular.py +++ /dev/null @@ -1,20 +0,0 @@ -import pyblish.api -import colorbleed.api - - -class ValidateUnitsAngular(pyblish.api.ContextPlugin): - """Scene angular units must be in degrees""" - - order = colorbleed.api.ValidateSceneOrder - label = "Units (angular)" - families = ["colorbleed.rig", - "colorbleed.model", - "colorbleed.pointcache", - "colorbleed.curves"] - - def process(self, context): - units = context.data('angularUnits') - - self.log.info('Units (angular): {0}'.format(units)) - assert units and units == 'deg', ( - "Scene angular units must be degrees") diff --git a/colorbleed/plugins/maya/publish/_validate_units_fps.py b/colorbleed/plugins/maya/publish/_validate_units_fps.py deleted file mode 100644 index b28c86804e..0000000000 --- a/colorbleed/plugins/maya/publish/_validate_units_fps.py +++ /dev/null @@ -1,28 +0,0 @@ -import pyblish.api -import colorbleed.api - - -class ValidateUnitsFps(pyblish.api.ContextPlugin): - """Validate the scene linear, angular and time units.""" - - order = colorbleed.api.ValidateSceneOrder - label = "Units (fps)" - families = ["colorbleed.rig", - "colorbleed.pointcache", - "colorbleed.curves"] - actions = [colorbleed.api.RepairAction] - optional = True - - def process(self, context): - - fps = context.data['fps'] - - self.log.info('Units (time): {0} FPS'.format(fps)) - assert fps and fps == 25.0, "Scene must be 25 FPS" - - @classmethod - def repair(cls): - """Fix the current FPS setting of the scene, set to PAL(25.0 fps) - """ - import maya.cmds as cmds - cmds.currentUnit(time="pal") diff --git a/colorbleed/plugins/maya/publish/_validate_units_linear.py b/colorbleed/plugins/maya/publish/_validate_units_linear.py deleted file mode 100644 index 9230ae7626..0000000000 --- a/colorbleed/plugins/maya/publish/_validate_units_linear.py +++ /dev/null @@ -1,20 +0,0 @@ -import pyblish.api -import colorbleed.api - - -class ValidateUnitsLinear(pyblish.api.ContextPlugin): - """Scene must be in linear units""" - - order = colorbleed.api.ValidateSceneOrder - label = "Units (linear)" - families = ["colorbleed.rig", - "colorbleed.model", - "colorbleed.pointcache", - "colorbleed.curves"] - - def process(self, context): - units = context.data('linearUnits') - - self.log.info('Units (linear): {0}'.format(units)) - assert units and units == 'cm', ("Scene linear units must " - "be centimeters") diff --git a/colorbleed/plugins/maya/publish/collect_current_file.py b/colorbleed/plugins/maya/publish/collect_current_file.py index 305116fb2d..0b38ebcf3d 100644 --- a/colorbleed/plugins/maya/publish/collect_current_file.py +++ b/colorbleed/plugins/maya/publish/collect_current_file.py @@ -1,5 +1,3 @@ -import os - from maya import cmds import pyblish.api @@ -15,4 +13,4 @@ class CollectMayaCurrentFile(pyblish.api.ContextPlugin): def process(self, context): """Inject the current working file""" current_file = cmds.file(query=True, sceneName=True) - context.data['currentFile'] = os.path.normpath(current_file) + context.data['currentFile'] = current_file diff --git a/colorbleed/plugins/maya/publish/validate_maya_units.py b/colorbleed/plugins/maya/publish/validate_maya_units.py index 538dec949c..383562cef2 100644 --- a/colorbleed/plugins/maya/publish/validate_maya_units.py +++ b/colorbleed/plugins/maya/publish/validate_maya_units.py @@ -1,3 +1,5 @@ +import maya.cmds as cmds + import pyblish.api import colorbleed.api @@ -11,7 +13,7 @@ class ValidateMayaUnits(pyblish.api.ContextPlugin): "colorbleed.model", "colorbleed.pointcache", "colorbleed.curves"] - actions = [colorbleed.api.RepairAction] + actions = [colorbleed.api.RepairContextAction] def process(self, context): @@ -29,11 +31,23 @@ class ValidateMayaUnits(pyblish.api.ContextPlugin): assert angularunits and angularunits == 'deg', ("Scene angular units " "must be degrees") - - assert fps and fps == 25.0, "Scene must be 25 FP" + assert fps and fps == 25.0, "Scene must be 25 FPS" @classmethod def repair(cls): - """Fix the current FPS setting of the scene, set to PAL(25.0 fps) - """ - raise NotImplementedError() + """Fix the current FPS setting of the scene, set to PAL(25.0 fps)""" + + cls.log.info("Setting angular unit to 'degrees'") + cmds.currentUnit(angle="degree") + current_angle = cmds.currentUnit(query=True, angle=True) + cls.log.debug(current_angle) + + cls.log.info("Setting linear unit to 'centimeter'") + cmds.currentUnit(linear="centimeter") + current_linear = cmds.currentUnit(query=True, linear=True) + cls.log.debug(current_linear) + + cls.log.info("Setting time unit to 'PAL'") + cmds.currentUnit(time="pal") + current_time = cmds.currentUnit(query=True, time=True) + cls.log.debug(current_time) diff --git a/colorbleed/plugins/maya/publish/validate_rig_contents.py b/colorbleed/plugins/maya/publish/validate_rig_contents.py index 1b6beb8ad7..6ebf807762 100644 --- a/colorbleed/plugins/maya/publish/validate_rig_contents.py +++ b/colorbleed/plugins/maya/publish/validate_rig_contents.py @@ -1,3 +1,5 @@ +from maya import cmds + import pyblish.api import colorbleed.api @@ -19,17 +21,14 @@ class ValidateRigContents(pyblish.api.InstancePlugin): def process(self, instance): - from maya import cmds - - objsets = ("controls_SET", "out_SET") + objectsets = ("controls_SET", "out_SET") missing = list() - for objset in objsets: - if objset not in instance: - missing.append(objset) + for objectset in objectsets: + if objectset not in instance: + missing.append(objectset) - assert not missing, ("%s is missing %s" - % (instance, missing)) + assert not missing, ("%s is missing %s" % (instance, missing)) # Ensure there are at least some transforms or dag nodes # in the rig instance