Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2062 from Ellipsanime/add-maya-pyblish-plugins
Browse files Browse the repository at this point in the history
Maya: validate authorized loaded plugins
  • Loading branch information
mkolar authored Oct 1, 2021
2 parents 93e9822 + cd05b01 commit 783a4c1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
47 changes: 47 additions & 0 deletions openpype/hosts/maya/plugins/publish/validate_loaded_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pyblish.api
import maya.cmds as cmds
import openpype.api
import os


class ValidateLoadedPlugin(pyblish.api.ContextPlugin):
"""Ensure there are no unauthorized loaded plugins"""

label = "Loaded Plugin"
order = pyblish.api.ValidatorOrder
host = ["maya"]
actions = [openpype.api.RepairContextAction]

@classmethod
def get_invalid(cls, context):

invalid = []
loaded_plugin = cmds.pluginInfo(query=True, listPlugins=True)
# get variable from OpenPype settings
whitelist_native_plugins = cls.whitelist_native_plugins
authorized_plugins = cls.authorized_plugins or []

for plugin in loaded_plugin:
if not whitelist_native_plugins and os.getenv('MAYA_LOCATION') \
in cmds.pluginInfo(plugin, query=True, path=True):
continue
if plugin not in authorized_plugins:
invalid.append(plugin)

return invalid

def process(self, context):

invalid = self.get_invalid(context)
if invalid:
raise RuntimeError(
"Found forbidden plugin name: {}".format(", ".join(invalid))
)

@classmethod
def repair(cls, context):
"""Unload forbidden plugins"""

for plugin in cls.get_invalid(context):
cmds.pluginInfo(plugin, edit=True, autoload=False)
cmds.unloadPlugin(plugin, force=True)
5 changes: 5 additions & 0 deletions openpype/settings/defaults/project_settings/maya.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
"enabled": false,
"attributes": {}
},
"ValidateLoadedPlugin": {
"enabled": false,
"whitelist_native_plugins": false,
"authorized_plugins": []
},
"ValidateRenderSettings": {
"arnold_render_attributes": [],
"vray_render_attributes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@
]
},

{
"type": "dict",
"collapsible": true,
"key": "ValidateLoadedPlugin",
"label": "Validate Loaded Plugin",
"checkbox_key": "enabled",
"children": [
{
"type": "boolean",
"key": "enabled",
"label": "Enabled"
},
{
"type": "boolean",
"key": "whitelist_native_plugins",
"label": "Whitelist Maya Native Plugins"
},
{
"type": "list",
"key": "authorized_plugins",
"label": "Authorized plugins",
"object_type": "text"
}
]
},

{
"type": "dict",
"collapsible": true,
Expand Down

0 comments on commit 783a4c1

Please sign in to comment.