Exemplo n.º 1
0
    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
Exemplo n.º 2
0
def saveApiCache():
    startup.writeCache( ( apiCache.reservedMayaTypes, apiCache.reservedApiTypes,
                           apiCache.apiTypesToApiEnums, apiCache.apiEnumsToApiTypes,
                           apiCache.mayaTypesToApiTypes,
                           apiCache.apiTypesToApiClasses, apiCache.apiTypeHierarchy, apiCache.apiClassInfo ),
                        'mayaApi', 'the API cache' )
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def saveApiToMelBridge():
    # maya 8.5 fix: convert defaultdict to dict
    bridge = dict(apiToMelData)
    startup.writeCache( (bridge,apiClassOverrides), 'mayaApiMelBridge', 'the api-mel bridge', useVersion=False )
Exemplo n.º 5
0
                    else:
                        newlines.append('    ' + line )
                        if res is not None:
                            newlines.append( '    # Result: %r #' % (res,) )

            if evaluate:
                _logger.info("successful evaluation! %s", command)

            example = '\n'.join( newlines )
            processedExamples[command] = example
        except Exception, e:
            raise
            #_logger.info("FAILED: %s: %s" % (command, e) )
        else:
            # write out after each success so that if we crash we don't have to start from scratch
            startup.writeCache(processedExamples, 'mayaCmdsExamples', 'the Maya commands examples', useVersion=False)

        # cleanup opened windows
        for ui in set(cmds.lsUI(windows=True)).difference(openWindows):
            try: cmds.deleteUI(ui, window=True)
            except:pass

    _logger.info("Done Fixing Examples")

    # restore manipulators and anim options
    cmds.manipOptions( handleSize=manipOptions[0], scale=manipOptions[1] )
    cmds.animDisplay( e=1, timeCode=animOptions[0], timeCodeOffset=animOptions[1], modelUpdate=animOptions[2])

    #startup.writeCache('mayaCmdsExamples', examples, 'the Maya commands examples')