This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2062 from Ellipsanime/add-maya-pyblish-plugins
Maya: validate authorized loaded plugins
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
openpype/hosts/maya/plugins/publish/validate_loaded_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters