示例#1
0
文件: mdb.py 项目: adamcobabe/mrv
def createTypeNameToMfnClsMap( ):
	"""Parse a file associating node type names with the best compatible MFn function 
	set and return a dictionary with the data
	
	:return: dict(((nodeTypeNameStr : api.MFnCls), ...)) dictionary with nodetypeName
		MFn class mapping"""
	typenameToClsMap = dict()
	
	cfile = cacheFilePath( "nodeTypeToMfnCls", "map" )
	fobj = open( cfile, 'r' )
	pf = PipeSeparatedFile( fobj )

	version = pf.beginReading( )	 # don't care about version
	for nodeTypeName, mfnTypeName in pf.readColumnLine( ):
		found = False
		for apimod in apiModules():
			try:
				typenameToClsMap[ nodeTypeName ] = getattr( apimod, mfnTypeName )
				found = True
				break				# it worked, there is only one matching class
			except AttributeError:
				pass
		# END for each api module
		if not found:
			log.debug("Couldn't find mfn class named %s" % mfnTypeName)
	# END for each type/mfnclass pair
	fobj.close()
	
	return typenameToClsMap
示例#2
0
def createTypeNameToMfnClsMap():
    """Parse a file associating node type names with the best compatible MFn function 
	set and return a dictionary with the data
	
	:return: dict(((nodeTypeNameStr : api.MFnCls), ...)) dictionary with nodetypeName
		MFn class mapping"""
    typenameToClsMap = dict()

    cfile = cacheFilePath("nodeTypeToMfnCls", "map")
    fobj = open(cfile, 'r')
    pf = PipeSeparatedFile(fobj)

    version = pf.beginReading()  # don't care about version
    for nodeTypeName, mfnTypeName in pf.readColumnLine():
        found = False
        for apimod in apiModules():
            try:
                typenameToClsMap[nodeTypeName] = getattr(apimod, mfnTypeName)
                found = True
                break  # it worked, there is only one matching class
            except AttributeError:
                pass
        # END for each api module
        if not found:
            log.debug("Couldn't find mfn class named %s" % mfnTypeName)
    # END for each type/mfnclass pair
    fobj.close()

    return typenameToClsMap
示例#3
0
def initializeNewMayaRelease( ):
    """This method should be called once a new maya release is encountered. It will
    initialize and update the database as well as possible, and give instructions 
    on what to do next.
    
    :note: Will not run if any user setup is performed as we need a clean maya 
    without any plugins loaded.
    :raise EnvironmentError: if the current maya version has already been initialized
    or if the user setup was executed"""
    if int(os.environ.get('MRV_STANDALONE_AUTOLOAD_PLUGINS', 0)) or \
        int(os.environ.get('MRV_STANDALONE_RUN_USER_SETUP', 0)):
        raise EnvironmentError("Cannot operate if custom user setup was performed")
    # END check environments
    
    import env
    import mdb

    nodeshf = mdb.nodeHierarchyFile()
    app_version = env.appVersion()[0]
    if nodeshf.isfile():
        raise EnvironmentError("Maya version %g already initialized as hierarchy file at %s does already exist" % (app_version, nodeshf))
    # END assure we are not already initialized
    
    # UPDATE MFN DB FILES
    #####################
    # Get all MFn function sets and put in their new versions as well as files
    mdb.writeMfnDBCacheFiles()
    
    # UPDATE NODE HIERARCHY FILE
    ############################
    # create all node types, one by one, and query their hierarchy relationship.
    # From that info, generate a dagtree which is written to the hierarchy file.
    # NOTE: for now we just copy the old one
    dagTree, typeToMFnList = mdb.generateNodeHierarchy()
    dagTree.to_hierarchy_file('_root_', mdb.nodeHierarchyFile())
    
    # UPDATE MFN ASSOCIATIONS
    #########################
    fp = open(mdb.cacheFilePath('nodeTypeToMfnCls', 'map'), 'wb')
    mla = reduce(max, (len(t[0]) for t in typeToMFnList))
    mlb = reduce(max, (len(t[1]) for t in typeToMFnList))
    
    psf = PipeSeparatedFile(fp)
    psf.beginWriting((mla, mlb))
    for token in typeToMFnList:
        psf.writeTokens(token)
    # END for each line to write
    fp.close()
    
    
    # PROVIDE INFO  TO THE USER
    ############################
    print >> sys.stderr, "1. git status might reveals new MFnFunction sets as untracked files - check the new methods and possibly define aliases (or delete them wiht 'x')"
    print >> sys.stderr, "2. Check the 'whats new' part of the maya docs for important API changes and possibly incorporate them into the code"
    print >> sys.stderr, "3. run 'tmrv %g' and fix possibly breaking tests or the code being tested" % app_version
    print >> sys.stderr, "4. run 'tmrvr' to assure all maya versions are still working - ideally on all platforms."
    print >> sys.stderr, "5. run the UI tests and assure that they don't fail"
    print >> sys.stderr, "6. Commit and push your changes - you are done"
示例#4
0
文件: mdb.py 项目: adamcobabe/mrv
	def _initFromFile( self, filepath ):
		"""Initialize the database with values from the given file
		
		:note: the file must have been written using the `writeToFile` method"""
		self.clear()
		fobj = open( filepath, 'r' )

		pf = PipeSeparatedFile( fobj )
		pf.beginReading( )
		
		# get the entries
		for tokens in pf.readColumnLine( ):
			key = tokens[ 1 ]
			self[ key ] = MMethodDescriptor( flag=tokens[0], rvalfunc=tokens[2], newname=tokens[3] )
示例#5
0
文件: mdb.py 项目: adamcobabe/mrv
	def writeToFile( self, filepath ):
		"""Write our database contents to the given file"""
		klist = self.keys()
		klist.sort()

		fobj = open( filepath, 'w' )
		pf = PipeSeparatedFile( fobj )
		pf.beginWriting( ( 4,40,20,40 ) )

		for key in klist:							# write entries
			e = self[ key ]
			pf.writeTokens( ( e.flag, key,e.rvalfunc, e.newname ) )
		# end for each key

		fobj.close()
示例#6
0
    def _initFromFile(self, filepath):
        """Initialize the database with values from the given file
		
		:note: the file must have been written using the `writeToFile` method"""
        self.clear()
        fobj = open(filepath, 'r')

        pf = PipeSeparatedFile(fobj)
        pf.beginReading()

        # get the entries
        for tokens in pf.readColumnLine():
            key = tokens[1]
            self[key] = MMethodDescriptor(flag=tokens[0],
                                          rvalfunc=tokens[2],
                                          newname=tokens[3])
示例#7
0
文件: __init__.py 项目: kthulhu/mrv
def initializeNewMayaRelease():
    """This method should be called once a new maya release is encountered. It will
	initialize and update the database as well as possible, and give instructions 
	on what to do next.
	
	:note: Will not run if any user setup is performed as we need a clean maya 
	without any plugins loaded.
	:raise EnvironmentError: if the current maya version has already been initialized
	or if the user setup was executed"""
    if int(os.environ.get('MRV_STANDALONE_AUTOLOAD_PLUGINS', 0)) or \
     int(os.environ.get('MRV_STANDALONE_RUN_USER_SETUP', 0)):
        raise EnvironmentError(
            "Cannot operate if custom user setup was performed")
    # END check environments

    import env
    import mdb

    nodeshf = mdb.nodeHierarchyFile()
    app_version = env.appVersion()[0]
    if nodeshf.isfile():
        raise EnvironmentError(
            "Maya version %g already initialized as hierarchy file at %s does already exist"
            % (app_version, nodeshf))
    # END assure we are not already initialized

    # UPDATE MFN DB FILES
    #####################
    # Get all MFn function sets and put in their new versions as well as files
    mdb.writeMfnDBCacheFiles()

    # UPDATE NODE HIERARCHY FILE
    ############################
    # create all node types, one by one, and query their hierarchy relationship.
    # From that info, generate a dagtree which is written to the hierarchy file.
    # NOTE: for now we just copy the old one
    dagTree, typeToMFnList = mdb.generateNodeHierarchy()
    dagTree.to_hierarchy_file('_root_', mdb.nodeHierarchyFile())

    # UPDATE MFN ASSOCIATIONS
    #########################
    fp = open(mdb.cacheFilePath('nodeTypeToMfnCls', 'map'), 'wb')
    mla = reduce(max, (len(t[0]) for t in typeToMFnList))
    mlb = reduce(max, (len(t[1]) for t in typeToMFnList))

    psf = PipeSeparatedFile(fp)
    psf.beginWriting((mla, mlb))
    for token in typeToMFnList:
        psf.writeTokens(token)
    # END for each line to write
    fp.close()

    # PROVIDE INFO	TO THE USER
    ############################
    print >> sys.stderr, "1. git status might reveals new MFnFunction sets as untracked files - check the new methods and possibly define aliases (or delete them wiht 'x')"
    print >> sys.stderr, "2. Check the 'whats new' part of the maya docs for important API changes and possibly incorporate them into the code"
    print >> sys.stderr, "3. run 'tmrv %g' and fix possibly breaking tests or the code being tested" % app_version
    print >> sys.stderr, "4. run 'tmrvr' to assure all maya versions are still working - ideally on all platforms."
    print >> sys.stderr, "5. run the UI tests and assure that they don't fail"
    print >> sys.stderr, "6. Commit and push your changes - you are done"
示例#8
0
    def writeToFile(self, filepath):
        """Write our database contents to the given file"""
        klist = self.keys()
        klist.sort()

        fobj = open(filepath, 'w')
        pf = PipeSeparatedFile(fobj)
        pf.beginWriting((4, 40, 20, 40))

        for key in klist:  # write entries
            e = self[key]
            pf.writeTokens((e.flag, key, e.rvalfunc, e.newname))
        # end for each key

        fobj.close()