def _mergeClassOverrides(self, bridgeCache=None): if bridgeCache is None: bridgeCache = ApiMelBridgeCache() bridgeCache.build() _util.mergeCascadingDicts(bridgeCache.apiClassOverrides, self.apiClassInfo, allowDictToListMerging=True)
def build(self, rebuildAllButClassInfo=False): """ Used to rebuild api cache, either by loading from a cache file, or rebuilding from scratch. Set 'rebuildAllButClassInfo' to True to force rebuilding of all info BUT self.apiClassInfo - this is useful for versions < 2009, as these versions cannot parse the api docs; by setting this to False, you can rebuild all other api information. """ # Need to initialize this to possibly pass into _buildself.apiTypeHierarchy, if rebuildAllButClassInfo self.apiClassInfo = None data = startup.loadCache( 'mayaApi', 'the API cache', compressed=True ) self._buildMayaReservedTypes() if data is not None: #self.reservedMayaTypes = data[0] #self.reservedApiTypes = data[1] self.apiTypesToApiEnums = data[2] self.apiEnumsToApiTypes = data[3] self.mayaTypesToApiTypes = data[4] self.apiTypesToApiClasses = data[5] self.apiTypeHierarchy = data[6] self.apiClassInfo = data[7] if not rebuildAllButClassInfo: # Note that even if rebuildAllButClassInfo, we still want to load # the cache file, in order to grab self.apiClassInfo return _logger.info( "Rebuilding the API Caches..." ) # fill out the data structures self._buildApiTypesList() #self.apiTypesToApiEnums, self.apiTypesToApiClasses = self._buildApiTypesList() #_buildMayaTypesList() if not rebuildAllButClassInfo: self.apiClassInfo = None self._buildApiTypeHierarchy() # merge in the manual overrides: we only do this when we're rebuilding or in the pymelControlPanel _logger.info( 'merging in dictionary of manual api overrides') _util.mergeCascadingDicts( apiClassOverrides, self.apiClassInfo, allowDictToListMerging=True ) startup.writeCache( ( self.reservedMayaTypes, self.reservedApiTypes, self.apiTypesToApiEnums, self.apiEnumsToApiTypes, self.mayaTypesToApiTypes, self.apiTypesToApiClasses, self.apiTypeHierarchy, self.apiClassInfo ), 'mayaApi', 'the API cache' ) return
def build(self): super(CmdCache, self).build() # corrections that are always made, to both loaded and freshly built caches util.mergeCascadingDicts(cmdlistOverrides, self.cmdlist) # add in any nodeCommands added after cache rebuild self.nodeCommandList = set(self.nodeCommandList).union(nodeTypeToNodeCommand.values()) self.nodeCommandList = sorted(self.nodeCommandList) for module, funcNames in moduleCommandAdditions.iteritems(): for funcName in funcNames: currModule = self.cmdlist[funcName]['type'] if currModule != module: self.cmdlist[funcName]['type'] = module id = self.moduleCmds[currModule].index(funcName) self.moduleCmds[currModule].pop(id) self.moduleCmds[module].append(funcName) return (self.cmdlist, self.nodeHierarchy, self.uiClassList, self.nodeCommandList, self.moduleCmds)
def _mergeClassOverrides(self, bridgeCache=None): if bridgeCache is None: bridgeCache = ApiMelBridgeCache() bridgeCache.build() _util.mergeCascadingDicts( bridgeCache.apiClassOverrides, self.apiClassInfo, allowDictToListMerging=True )
import sys THIS_FILE = os.path.normpath( os.path.abspath(inspect.getsourcefile(lambda: None))) THIS_DIR = os.path.dirname(THIS_FILE) PYMEL_ROOT = os.path.dirname(THIS_DIR) sys.path.insert(0, PYMEL_ROOT) import pymel.internal.apicache as apicache import pymel.internal.startup import pymel.util as _util logger = pymel.internal.startup._logger bridgeCache = apicache.ApiMelBridgeCache() bridgeCache.load() print("read: {}".format(bridgeCache.path())) for version in apicache.ApiCache.allVersions(): cacheInst = apicache.ApiCache() cacheInst.version = version cacheInst.load() print("updating: {}".format(cacheInst.path())) _util.mergeCascadingDicts(bridgeCache.apiClassOverrides, cacheInst.apiClassInfo, allowDictToListMerging=True) cacheInst.save()
def buildCachedData() : """Build and save to disk the list of Maya Python commands and their arguments""" # With extension can't get docs on unix 64 # path is # /usr/autodesk/maya2008-x64/docs/Maya2008/en_US/Nodes/index_hierarchy.html # and not # /usr/autodesk/maya2008-x64/docs/Maya2008-x64/en_US/Nodes/index_hierarchy.html long_version = versions.installName() data = startup.loadCache( 'mayaCmdsList', 'the list of Maya commands' ) if data is not None: cmdlist,nodeHierarchy,uiClassList,nodeCommandList,moduleCmds = data else: # or not isinstance(cmdlist,list): cmdlist = {} _logger.info("Rebuilding the list of Maya commands...") nodeHierarchy = _getNodeHierarchy(long_version) nodeFunctions = [ x[0] for x in nodeHierarchy ] nodeFunctions += nodeTypeToNodeCommand.values() #nodeHierarchyTree = trees.IndexedTree(nodeHierarchy) uiClassList = UI_COMMANDS nodeCommandList = [] for moduleName, longname in moduleNameShortToLong.items(): moduleNameShortToLong[moduleName] = getModuleCommandList( longname, long_version ) tmpCmdlist = inspect.getmembers(cmds, callable) cmdlist = {} #moduleCmds = defaultdict(list) moduleCmds = dict( (k,[]) for k in moduleNameShortToLong.keys() ) moduleCmds.update( {'other':[], 'runtime': [], 'context': [], 'uiClass': [] } ) for funcName, data in tmpCmdlist : # determine to which module this function belongs module = None if funcName in ['eval', 'file', 'filter', 'help', 'quit']: module = None elif funcName.startswith('ctx') or funcName.endswith('Ctx') or funcName.endswith('Context'): module = 'context' #elif funcName in uiClassList: # module = 'uiClass' #elif funcName in nodeHierarchyTree or funcName in nodeTypeToNodeCommand.values(): # module = 'node' else: for moduleName, commands in moduleNameShortToLong.iteritems(): if funcName in commands: module = moduleName break if module is None: if mm.eval('whatIs "%s"' % funcName ) == 'Run Time Command': module = 'runtime' else: module = 'other' cmdInfo = {} if module: moduleCmds[module].append(funcName) if module != 'runtime': cmdInfo = getCmdInfo(funcName, long_version) if module != 'windows': if funcName in nodeFunctions: nodeCommandList.append(funcName) cmdInfo = testNodeCmd( funcName, cmdInfo, nodeCmd=True, verbose=True ) #elif module != 'context': # cmdInfo = testNodeCmd( funcName, cmdInfo, nodeCmd=False, verbose=True ) cmdInfo['type'] = module flags = getCallbackFlags(cmdInfo) if flags: cmdInfo['callbackFlags'] = flags cmdlist[funcName] = cmdInfo # # func, args, (usePyNode, baseClsName, nodeName) # # args = dictionary of command flags and their data # # usePyNode = determines whether the class returns its 'nodeName' or uses PyNode to dynamically return # # baseClsName = for commands which should generate a class, this is the name of the superclass to inherit # # nodeName = most creation commands return a node of the same name, this option is provided for the exceptions # try: # cmdlist[funcName] = args, pymelCmdsList[funcName] ) # except KeyError: # # context commands generate a class based on unicode (which is triggered by passing 'None' to baseClsName) # if funcName.startswith('ctx') or funcName.endswith('Ctx') or funcName.endswith('Context'): # cmdlist[funcName] = (funcName, args, (False, None, None) ) # else: # cmdlist[funcName] = (funcName, args, () ) # split the cached data for lazy loading cmdDocList = {} examples = {} for cmdName, cmdInfo in cmdlist.iteritems(): try: examples[cmdName] = cmdInfo.pop('example') except KeyError: pass newCmdInfo = {} if 'description' in cmdInfo: newCmdInfo['description'] = cmdInfo.pop('description') newFlagInfo = {} if 'flags' in cmdInfo: for flag, flagInfo in cmdInfo['flags'].iteritems(): newFlagInfo[flag] = { 'docstring' : flagInfo.pop('docstring') } newCmdInfo['flags'] = newFlagInfo if newCmdInfo: cmdDocList[cmdName] = newCmdInfo startup.writeCache( (cmdlist,nodeHierarchy,uiClassList,nodeCommandList,moduleCmds), 'mayaCmdsList', 'the list of Maya commands',compressed=True ) startup.writeCache( cmdDocList, 'mayaCmdsDocs', 'the Maya command documentation',compressed=True ) startup.writeCache( examples, 'mayaCmdsExamples', 'the list of Maya command examples',compressed=True ) # corrections that are always made, to both loaded and freshly built caches util.mergeCascadingDicts( cmdlistOverrides, cmdlist ) # add in any nodeCommands added after cache rebuild nodeCommandList = set(nodeCommandList).union(nodeTypeToNodeCommand.values()) nodeCommandList = sorted( nodeCommandList ) for module, funcNames in moduleCommandAdditions.iteritems(): for funcName in funcNames: currModule = cmdlist[funcName]['type'] if currModule != module: cmdlist[funcName]['type'] = module id = moduleCmds[currModule].index(funcName) moduleCmds[currModule].pop(id) moduleCmds[module].append(funcName) return (cmdlist,nodeHierarchy,uiClassList,nodeCommandList,moduleCmds)