<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import inspect <EOL> import hashlib <EOL> from collections import defaultdict <EOL> import maya . OpenMaya as om <EOL> import maya . OpenMayaMPx as mpx <EOL> import maya . cmds <EOL> mpxToEnumNames = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> mpxToEnum = { } <EOL> for nodeName , enumName in mpxToEnumNames . iteritems ( ) : <EOL> node = getattr ( mpx , nodeName , None ) <EOL> if node : <EOL> mpxToEnum [ node ] = getattr ( mpx . MPxNode , enumName ) <EOL> _enumToStr = None <EOL> def enumToStr ( ) : <EOL> '''<STR_LIT>''' <EOL> global _enumToStr <EOL> if _enumToStr is None : <EOL> _enumToStr = { } <EOL> for name , val in inspect . getmembers ( mpx . MPxNode , lambda x : isinstance ( x , int ) ) : <EOL> if name . startswith ( '<STR_LIT:k>' ) : <EOL> _enumToStr [ val ] = name <EOL> return _enumToStr <EOL> _allMPx = None <EOL> def allMPx ( ) : <EOL> '''<STR_LIT>''' <EOL> global _allMPx <EOL> if _allMPx is None : <EOL> _allMPx = [ ] <EOL> for _ , cls in inspect . getmembers ( mpx , lambda x : inspect . isclass ( x ) and issubclass ( x , mpx . MPxNode ) ) : <EOL> _allMPx . append ( cls ) <EOL> return _allMPx <EOL> for _mpx in allMPx ( ) : <EOL> assert _mpx in mpxToEnum , '<STR_LIT>' % _mpx . __name__ <EOL> registered = set ( ) <EOL> pyNodeMethods = { } <EOL> def _pluginModule ( ) : <EOL> return inspect . getmodule ( lambda : None ) <EOL> def _pluginName ( ) : <EOL> return _pluginModule ( ) . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> def _pluginFile ( ) : <EOL> return inspect . getsourcefile ( lambda : None ) <EOL> def _loadPlugin ( ) : <EOL> thisFile = _pluginFile ( ) <EOL> if not maya . cmds . pluginInfo ( thisFile , query = <NUM_LIT:1> , loaded = <NUM_LIT:1> ) : <EOL> maya . cmds . loadPlugin ( thisFile ) <EOL> def _unloadPlugin ( ) : <EOL> thisFile = _pluginFile ( ) <EOL> if maya . cmds . pluginInfo ( thisFile , query = <NUM_LIT:1> , loaded = <NUM_LIT:1> ) : <EOL> maya . cmds . unloadPlugin ( thisFile ) <EOL> def _getPlugin ( object = None ) : <EOL> if object is None : <EOL> _loadPlugin ( ) <EOL> mobject = mpx . MFnPlugin . findPlugin ( _pluginName ( ) ) <EOL> plugin = mpx . MFnPlugin ( mobject ) <EOL> elif isinstance ( object , om . MObject ) : <EOL> plugin = mpx . MFnPlugin ( object ) <EOL> elif isinstance ( object , mpx . MFnPlugin ) : <EOL> plugin = object <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return plugin <EOL> def initializePlugin ( mobject ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def uninitializePlugin ( mobject ) : <EOL> "<STR_LIT>" <EOL> global registered <EOL> mod = sys . modules [ '<STR_LIT>' ] <EOL> plugin = mpx . MFnPlugin ( mobject ) <EOL> for obj in registered : <EOL> print "<STR_LIT>" , obj . name ( ) <EOL> obj . deregisterCommand ( plugin ) <EOL> registered = set ( ) <EOL> class BasePluginMixin ( object ) : <EOL> _name = None <EOL> _mpxType = None <EOL> @ classmethod <EOL> def getMpxType ( cls ) : <EOL> if cls . _mpxType is None : <EOL> for pClass in inspect . getmro ( cls ) : <EOL> if pClass in mpxToEnum : <EOL> cls . _mpxType = pClass <EOL> break <EOL> return cls . _mpxType <EOL> @ classmethod <EOL> def mayaName ( cls ) : <EOL> if cls . _name is None : <EOL> cls . _name = cls . __name__ <EOL> return cls . _name <EOL> _typeId = None <EOL> @ classmethod <EOL> def getTypeId ( cls , nodeName = None ) : <EOL> if cls . _typeId is None : <EOL> if nodeName is None : <EOL> nodeName = cls . mayaName ( ) <EOL> cls . _typeId = cls . _devTypeIdHash ( nodeName ) <EOL> return cls . _typeId <EOL> @ classmethod <EOL> def _devTypeIdHash ( cls , name ) : <EOL> '''<STR_LIT>''' <EOL> start = <NUM_LIT> <EOL> end = <NUM_LIT> <EOL> size = ( end - start ) + <NUM_LIT:1> <EOL> md5 = hashlib . md5 ( ) <EOL> md5 . update ( name ) <EOL> id = start + long ( md5 . hexdigest ( ) , <NUM_LIT:16> ) % size <EOL> return om . MTypeId ( id ) <EOL> @ classmethod <EOL> def create ( cls ) : <EOL> return mpx . asMPxPtr ( cls ( ) ) <EOL> @ classmethod <EOL> def register ( cls , plugin = None ) : <EOL> """<STR_LIT>""" <EOL> global registered <EOL> useThisPlugin = ( plugin is None ) <EOL> mplugin = _getPlugin ( plugin ) <EOL> cls . _registerOverride ( mplugin , useThisPlugin ) <EOL> if useThisPlugin : <EOL> registered . add ( cls ) <EOL> @ classmethod <EOL> def _registerOverride ( cls , mplugin , useThisPlugin ) : <EOL> '''<STR_LIT>''' <EOL> return <EOL> @ classmethod <EOL> def deregister ( cls , plugin = None ) : <EOL> """<STR_LIT>""" <EOL> global registered <EOL> useThisPlugin = ( plugin is None ) <EOL> mplugin = _getPlugin ( plugin ) <EOL> cls . _deregisterOverride ( mplugin , useThisPlugin ) <EOL> if plugin is None : <EOL> registered . remove ( cls ) <EOL> @ classmethod <EOL> def _deregisterOverride ( cls , mplugin , useThisPlugin ) : <EOL> '''<STR_LIT>''' <EOL> return <EOL> class Command ( BasePluginMixin , mpx . MPxCommand ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def createSyntax ( cls ) : <EOL> return om . MSyntax ( ) <EOL> @ classmethod <EOL> def _registerOverride ( cls , mplugin , useThisPlugin ) : <EOL> name = cls . mayaName ( ) <EOL> mplugin . registerCommand ( name , cls . create , cls . createSyntax ) <EOL> if useThisPlugin : <EOL> import pymel . core <EOL> pymel . core . _addPluginCommand ( mplugin . name ( ) , name ) <EOL> @ classmethod <EOL> def _deregisterOverride ( cls , mplugin , useThisPlugin ) : <EOL> '''<STR_LIT>''' <EOL> name = cls . mayaName ( ) <EOL> mplugin . deregisterCommand ( name ) <EOL> if useThisPlugin : <EOL> import pymel . core <EOL> pymel . core . _removePluginCommand ( mplugin . name ( ) , name ) <EOL> class TransformationMatrix ( BasePluginMixin , mpx . MPxTransformationMatrix ) : <EOL> _typeId = None <EOL> @ classmethod <EOL> def register ( cls , plugin = None ) : pass <EOL> @ classmethod <EOL> def deregister ( cls , plugin = None ) : pass <EOL> class DependNode ( BasePluginMixin , mpx . MPxNode ) : <EOL> _typeEnum = None <EOL> _typeId = None <EOL> @ classmethod <EOL> def getTypeEnum ( cls ) : <EOL> if cls . _typeEnum is None : <EOL> cls . _typeEnum = mpxToEnum [ cls . getMpxType ( ) ] <EOL> return cls . _typeEnum <EOL> _classification = None <EOL> _callbacks = defaultdict ( list ) <EOL> @ classmethod <EOL> def initialize ( cls ) : <EOL> return <EOL> @ classmethod <EOL> def _registerOverride ( cls , mplugin , useThisPlugin ) : <EOL> nodeName = cls . mayaName ( ) <EOL> global pyNodeMethods <EOL> pluginPynodeMethods = pyNodeMethods . setdefault ( mplugin . name ( ) , { } ) <EOL> pluginPynodeMethods [ nodeName ] = { } <EOL> for _ , clsObj in inspect . getmembers ( cls ) : <EOL> if isinstance ( clsObj , PyNodeMethod ) : <EOL> pluginPynodeMethods [ nodeName ] [ clsObj . name ] = clsObj . func <EOL> cls . _nodeRegisterOverride ( nodeName , mplugin ) <EOL> if useThisPlugin : <EOL> import pymel . core <EOL> pymel . core . _addPluginNode ( mplugin . name ( ) , nodeName ) <EOL> for cbname , reg in [ <EOL> ( '<STR_LIT>' , om . MDGMessage . addTimeChangeCallback ) , <EOL> ( '<STR_LIT>' , om . MDGMessage . addForceUpdateCallback ) , <EOL> ( '<STR_LIT>' , om . MDGMessage . addNodeAddedCallback ) , <EOL> ( '<STR_LIT>' , om . MDGMessage . addNodeRemovedCallback ) , <EOL> ( '<STR_LIT>' , om . MDGMessage . addPreConnectionCallback ) ] : <EOL> if hasattr ( cls , cbname ) : <EOL> cb = getattr ( cls , cbname ) <EOL> cls . _callbacks [ nodeName ] . append ( reg ( cb , nodeName ) ) <EOL> @ classmethod <EOL> def _nodeRegisterOverride ( cls , nodeName , mplugin ) : <EOL> registerArgs = [ nodeName , cls . getTypeId ( ) , cls . create , cls . initialize , <EOL> cls . getTypeEnum ( ) ] <EOL> if cls . _classification : <EOL> registerArgs . append ( cls . _classification ) <EOL> mplugin . registerNode ( * registerArgs ) <EOL> @ classmethod <EOL> def _deregisterOverride ( cls , mplugin , useThisPlugin ) : <EOL> '''<STR_LIT>''' <EOL> nodeName = cls . mayaName ( ) <EOL> global pyNodeMethods <EOL> pyNodeMethods . get ( mplugin . name ( ) , { } ) . pop ( nodeName , None ) <EOL> mplugin . deregisterNode ( cls . getTypeId ( ) ) <EOL> if useThisPlugin : <EOL> import pymel . core <EOL> pymel . core . _removePluginNode ( mplugin . name ( ) , nodeName ) <EOL> for id in cls . _callbacks . pop ( nodeName , [ ] ) : <EOL> om . MMessage . removeCallback ( id ) <EOL> @ classmethod <EOL> def isAbstractClass ( cls ) : <EOL> return False <EOL> class CameraSet ( DependNode , mpx . MPxCameraSet ) : pass <EOL> class Constraint ( DependNode , mpx . MPxConstraint ) : pass <EOL> class DeformerNode ( DependNode , mpx . MPxDeformerNode ) : pass <EOL> class EmitterNode ( DependNode , mpx . MPxEmitterNode ) : pass <EOL> class FluidEmitterNode ( EmitterNode , mpx . MPxFluidEmitterNode ) : pass <EOL> class FieldNode ( DependNode , mpx . MPxFieldNode ) : pass <EOL> class HardwareShader ( DependNode , mpx . MPxHardwareShader ) : pass <EOL> class HwShaderNode ( DependNode , mpx . MPxHwShaderNode ) : pass <EOL> class IkSolverNode ( DependNode , mpx . MPxIkSolverNode ) : pass <EOL> class ImagePlane ( DependNode , mpx . MPxImagePlane ) : pass <EOL> class LocatorNode ( DependNode , mpx . MPxLocatorNode ) : pass <EOL> class ManipContainer ( DependNode , mpx . MPxManipContainer ) : pass <EOL> class ManipulatorNode ( DependNode , mpx . MPxManipulatorNode ) : pass <EOL> class ObjectSet ( DependNode , mpx . MPxObjectSet ) : pass <EOL> class ParticleAttributeMapperNode ( DependNode , mpx . MPxParticleAttributeMapperNode ) : pass <EOL> class PolyTrg ( DependNode , mpx . MPxPolyTrg ) : pass <EOL> class SpringNode ( DependNode , mpx . MPxSpringNode ) : pass <EOL> class SurfaceShape ( DependNode , mpx . MPxSurfaceShape ) : pass <EOL> class ComponentShape ( SurfaceShape , mpx . MPxComponentShape ) : pass <EOL> class Transform ( DependNode , mpx . MPxTransform ) : <EOL> _transformMatrix = TransformationMatrix <EOL> @ classmethod <EOL> def _nodeRegisterOverride ( cls , nodeName , mplugin ) : <EOL> registerArgs = [ nodeName , cls . getTypeId ( ) , cls . create , cls . initialize , <EOL> cls . _transformMatrix . create , <EOL> cls . _transformMatrix . getTypeId ( ) ] <EOL> if cls . _classification : <EOL> registerArgs . append ( cls . _classification ) <EOL> mplugin . registerTransform ( * registerArgs ) <EOL> if hasattr ( mpx , '<STR_LIT>' ) : <EOL> class RepMgr ( DependNode , mpx . MPxRepMgr ) : pass <EOL> if hasattr ( mpx , '<STR_LIT>' ) : <EOL> class Representation ( DependNode , mpx . MPxRepresentation ) : pass <EOL> class PyNodeMethod ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , func , name = None ) : <EOL> if name is None : <EOL> name = func . __name__ <EOL> self . func = func <EOL> self . name = name <EOL> def getPluginHierarchy ( ) : <EOL> '''<STR_LIT>''' <EOL> import pymel . internal . cmdcache as cmdcache <EOL> dummyClasses = createDummyNodePlugins ( ) <EOL> inheritances = { } <EOL> for pluginType , dummyClass in dummyClasses . iteritems ( ) : <EOL> nodeType = dummyClass . mayaName ( ) <EOL> dummyClass . register ( ) <EOL> try : <EOL> try : <EOL> inheritance = cmdcache . getInheritance ( nodeType ) <EOL> except cmdcache . ManipNodeTypeError : <EOL> continue <EOL> finally : <EOL> dummyClass . deregister ( ) <EOL> assert inheritance [ - <NUM_LIT:1> ] == nodeType <EOL> inheritances [ pluginType ] = inheritance [ <NUM_LIT:1> : ] <EOL> return inheritances <EOL> def createDummyNodePlugins ( ) : <EOL> '''<STR_LIT>''' <EOL> pymelPlugClasses = [ ] <EOL> for obj in globals ( ) . itervalues ( ) : <EOL> if inspect . isclass ( obj ) and issubclass ( obj , DependNode ) : <EOL> pymelPlugClasses . append ( obj ) <EOL> dummyClasses = { } <EOL> for cls in pymelPlugClasses : <EOL> class DummyClass ( cls ) : <EOL> _name = '<STR_LIT>' + cls . __name__ <EOL> DummyClass . __name__ = '<STR_LIT>' + cls . __name__ <EOL> dummyClasses [ DummyClass . getMpxType ( ) ] = DummyClass <EOL> return dummyClasses <EOL> def mayaPlugins ( ) : <EOL> '''<STR_LIT>''' <EOL> import pymel . mayautils <EOL> mayaLoc = pymel . mayautils . getMayaLocation ( ) <EOL> plugins = [ ] <EOL> pluginPaths = [ os . path . realpath ( x ) for x in os . environ [ '<STR_LIT>' ] . split ( os . path . pathsep ) ] <EOL> for pluginPath in [ x for x in pluginPaths if x . startswith ( mayaLoc ) and os . path . isdir ( x ) ] : <EOL> for x in os . listdir ( pluginPath ) : <EOL> if os . path . isfile ( os . path . join ( pluginPath , x ) ) : <EOL> if not maya . cmds . pluginInfo ( x , q = <NUM_LIT:1> , loaded = <NUM_LIT:1> ) : <EOL> plugins . append ( x ) <EOL> return plugins <EOL> def loadAllMayaPlugins ( ) : <EOL> '''<STR_LIT>''' <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> for plugin in mayaPlugins ( ) : <EOL> try : <EOL> maya . cmds . loadPlugin ( plugin , quiet = <NUM_LIT:1> ) <EOL> except RuntimeError : pass <EOL> logger . debug ( "<STR_LIT>" ) <EOL> def unloadAllPlugins ( skipErrors = False , exclude = ( '<STR_LIT>' , ) ) : <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> loadedPlugins = maya . cmds . pluginInfo ( q = True , listPlugins = True ) <EOL> if loadedPlugins : <EOL> for plug in loadedPlugins : <EOL> if plug in exclude : <EOL> continue <EOL> logger . debug ( "<STR_LIT>" % plug ) <EOL> try : <EOL> maya . cmds . unloadPlugin ( plug , force = True ) <EOL> except Exception : <EOL> if skipErrors : <EOL> import traceback <EOL> logger . warning ( "<STR_LIT>" % plug ) <EOL> logger . warning ( traceback . format_exc ( ) ) <EOL> else : <EOL> raise <EOL> logger . debug ( "<STR_LIT>" ) <EOL> UNREPORTED_COMMANDS = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : [ '<STR_LIT>' ] } , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : { } , <EOL> } <EOL> def pluginCommands ( pluginName , reportedOnly = False ) : <EOL> '''<STR_LIT>''' <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> commands = [ ] <EOL> for cmdType , pluginToCmds in UNREPORTED_COMMANDS . iteritems ( ) : <EOL> try : <EOL> moreCmds = maya . cmds . pluginInfo ( pluginName , query = <NUM_LIT:1> , ** { cmdType : <NUM_LIT:1> } ) <EOL> except TypeError : <EOL> if reportedOnly : <EOL> moreCmds = [ ] <EOL> else : <EOL> moreCmds = pluginToCmds . get ( pluginName , [ ] ) <EOL> except Exception : <EOL> logger . error ( "<STR_LIT>" % ( cmdType , pluginName ) ) <EOL> moreCmds = [ ] <EOL> if moreCmds : <EOL> commands . extend ( moreCmds ) <EOL> return commands </s>
