Example #1
0
 def _wrapStaticMembers( cls, newcls, mfncls ):
     """Find static mfnmethods - if these are available, initialize the 
     mfn database for the given function set ( ``mfncls`` ) and create properly 
     wrapped methods. 
     Additionally check for enumerations, and generate the respective enumeration
     instances
     :note: As all types are initialized on startup, the staticmethods check 
         will load in quite a few function sets databases as many will have static 
         methods. There is no real way around it, but one could introduce 'packs'
         to bundle these together and load them only once. Probably the performance
         hit is not noticeable, but lets just say that I am aware of it
     :note: Currently method aliases are not implemented for statics !"""
     fstatic, finst = mdb.extractMFnFunctions(mfncls)
     hasEnum = mdb.hasMEnumeration(mfncls)
     if not fstatic and not hasEnum:
         return
         
     mfndb = cls._fetchMfnDB(newcls, mfncls, parse_enums=hasEnum)
     if fstatic:
         mfnname = mfncls.__name__
         for fs in fstatic:
             fn = fs.__name__
             if fn.startswith(mfnname):
                 fn = fn[len(mfnname)+1:]    # cut MFnName_methodName
             # END handle name prefix
             
             static_function = cls._wrapMfnFunc(newcls, mfncls, fn, mfndb)
             type.__setattr__(newcls, fn, staticmethod(static_function))
         # END for each static method
     # END handle static functions
     
     
     if hasEnum:
         for ed in mfndb.enums:
             type.__setattr__(newcls, ed.name, MEnumeration.create(ed, mfncls))
Example #2
0
	def _wrapStaticMembers( cls, newcls, mfncls ):
		"""Find static mfnmethods - if these are available, initialize the 
		mfn database for the given function set ( ``mfncls`` ) and create properly 
		wrapped methods. 
		Additionally check for enumerations, and generate the respective enumeration
		instances
		:note: As all types are initialized on startup, the staticmethods check 
			will load in quite a few function sets databases as many will have static 
			methods. There is no real way around it, but one could introduce 'packs'
			to bundle these together and load them only once. Probably the performance
			hit is not noticeable, but lets just say that I am aware of it
		:note: Currently method aliases are not implemented for statics !"""
		fstatic, finst = mdb.extractMFnFunctions(mfncls)
		hasEnum = mdb.hasMEnumeration(mfncls)
		if not fstatic and not hasEnum:
			return
			
		mfndb = cls._fetchMfnDB(newcls, mfncls, parse_enums=hasEnum)
		if fstatic:
			mfnname = mfncls.__name__
			for fs in fstatic:
				fn = fs.__name__
				if fn.startswith(mfnname):
					fn = fn[len(mfnname)+1:]	# cut MFnName_methodName
				# END handle name prefix
				
				static_function = cls._wrapMfnFunc(newcls, mfncls, fn, mfndb)
				type.__setattr__(newcls, fn, staticmethod(static_function))
			# END for each static method
		# END handle static functions
		
		
		if hasEnum:
			for ed in mfndb.enums:
				type.__setattr__(newcls, ed.name, MEnumeration.create(ed, mfncls))
Example #3
0
def prefetchMFnMethods():
    """Fetch and install all mfn methods on all types supporting a function set.
    This should only be done to help interactive mode, but makes absolutely no 
    sense in the default mode of operation when everything is produced on demand.
    
    :note: Attaches docstrings as well
    :return: integer representing the number of generated methods"""
    log.info("Prefetching all MFnMethods")
    
    num_fetched = 0
    for typename, mfncls in nodeTypeToMfnClsMap.iteritems():
        try:
            nodetype = _nodesdict[capitalize(typename)]
        except KeyError:
            log.debug("MFn methods for %s exists, but type was not found in nt" % typename)
            continue
        # END handle type exceptions
        
        mfnname = mfncls.__name__
        mfndb = MetaClassCreatorNodes._fetchMfnDB(nodetype, mfncls)
        fstatic, finst = mdb.extractMFnFunctions(mfncls)
        
        def set_method_if_possible(cls, fn, f):
            if not hasattr(cls, fn):
                type.__setattr__(cls, fn, f)
            # END overwrite protection
        # END utility 
        
        for f in finst:
            fn = f.__name__
            if fn.startswith(mfnname):
                fn = fn[len(mfnname)+1:]
            # END handle prefixed names
            
            fna = fn        # alias for method 
            try:
                origname, entry = mfndb.methodByName(fn)
                fna = entry.newname
            except KeyError:
                pass
            # END get alias metadata
            
            fwrapped = MetaClassCreatorNodes._wrapMfnFunc(nodetype, mfncls, fn, mfndb, mdb.PythonMFnCodeGenerator.kWithDocs)
            
            # could have been deleted
            if fwrapped is None:
                continue
            
            set_method_if_possible(nodetype, fn, fwrapped)
            if fna != fn:
                set_method_if_possible(nodetype, fna, fwrapped)
            # END handle aliases
            
            num_fetched += 1
        # END for each instance function
    # END for each type/mfncls pair
    
    return num_fetched
Example #4
0
def prefetchMFnMethods():
	"""Fetch and install all mfn methods on all types supporting a function set.
	This should only be done to help interactive mode, but makes absolutely no 
	sense in the default mode of operation when everything is produced on demand.
	
	:note: Attaches docstrings as well
	:return: integer representing the number of generated methods"""
	log.info("Prefetching all MFnMethods")
	
	num_fetched = 0
	for typename, mfncls in nodeTypeToMfnClsMap.iteritems():
		try:
			nodetype = _nodesdict[capitalize(typename)]
		except KeyError:
			log.debug("MFn methods for %s exists, but type was not found in nt" % typename)
			continue
		# END handle type exceptions
		
		mfnname = mfncls.__name__
		mfndb = MetaClassCreatorNodes._fetchMfnDB(nodetype, mfncls)
		fstatic, finst = mdb.extractMFnFunctions(mfncls)
		
		def set_method_if_possible(cls, fn, f):
			if not hasattr(cls, fn):
				type.__setattr__(cls, fn, f)
			# END overwrite protection
		# END utility 
		
		for f in finst:
			fn = f.__name__
			if fn.startswith(mfnname):
				fn = fn[len(mfnname)+1:]
			# END handle prefixed names
			
			fna = fn		# alias for method 
			try:
				origname, entry = mfndb.methodByName(fn)
				fna = entry.newname
			except KeyError:
				pass
			# END get alias metadata
			
			fwrapped = MetaClassCreatorNodes._wrapMfnFunc(nodetype, mfncls, fn, mfndb, mdb.PythonMFnCodeGenerator.kWithDocs)
			
			# could have been deleted
			if fwrapped is None:
				continue
			
			set_method_if_possible(nodetype, fn, fwrapped)
			if fna != fn:
				set_method_if_possible(nodetype, fna, fwrapped)
			# END handle aliases
			
			num_fetched += 1
		# END for each instance function
	# END for each type/mfncls pair
	
	return num_fetched