示例#1
0
    def BlockModelAdapter(cls, label="", specific_behavior=""):
        """ Return block model considering its class hierarchy
			The implementation depends only of the argument of the class. There is no dependance with the collector module (in comment bellow)
		"""
        from Container import DiskGUI, ScopeGUI, CodeBlock
        #from  Domain.Collector import *
        #if issubclass(cls, QuickScope.QuickScope):
        #m = ScopeGUI(label)
        #elif issubclass(cls, (To_Disk.To_Disk, Messagecollector.Messagecollector)):
        #m = DiskGUI(label)
        #else:
        ## mew CodeBlock instance
        #m = CodeBlock()

        # associated python class membre

        clsmbr = getClassMember(inspect.getfile(cls))

        ### args of class
        args = GetArgs(cls)

        ### find if there is filename param on the constructor and if there is no extention
        L = [os.path.isabs(str(a)) for a in list(args.values())]
        filename_without_ext_flag = L.index(True) if True in L else -1
        ### if there is a filename and if there is no extention -> its a to disk like object
        disk_model = filename_without_ext_flag >= 0 and not os.path.splitext(
            list(args.values())[filename_without_ext_flag])[-1] != ''

        ### find if scope is present in class name
        match = [
            re.match('[-_a-zA-z]*scope[-_a-zA-z]*', s, re.IGNORECASE)
            for s in list(clsmbr.keys()) + [specific_behavior]
        ]
        scope_model = [
            a.group(0) for a in [s for s in match if s is not None]
        ] != []

        ### find if messagecollector is present in class name
        match = [
            re.match('[-_a-zA-z]*collector[-_a-zA-z]*', s, re.IGNORECASE)
            for s in list(clsmbr.keys()) + [specific_behavior]
        ]
        messagecollector_model = [
            a.group(0) for a in [s for s in match if s is not None]
        ] != []

        # new codeBlcok instance
        if disk_model or messagecollector_model:
            m = DiskGUI(label)
        elif scope_model:
            m = ScopeGUI(label)
        else:
            m = CodeBlock(label)

        # define behavioral args from python class
        m.args = args

        return m
示例#2
0
	def BlockModelAdapter(cls, label="", specific_behavior=""):
		""" Return block model considering its class hierarchy
			The implementation depends only of the argument of the class. There is no dependance with the collector module (in comment bellow)
		"""
		from Container import DiskGUI, ScopeGUI, CodeBlock
		#from  Domain.Collector import *
		#if issubclass(cls, QuickScope.QuickScope):
				#m = ScopeGUI(label)
			#elif issubclass(cls, (To_Disk.To_Disk, Messagecollector.Messagecollector)):
				#m = DiskGUI(label)
			#else:
				## mew CodeBlock instance
				#m = CodeBlock()

		# associated python class membre

		clsmbr = getClassMember(inspect.getfile(cls))

		### args of class
		args = GetArgs(cls)

		### find if there is filename param on the constructor and if there is no extention
		L = map(lambda a: os.path.isabs(str(a)), args.values())
		filename_without_ext_flag = L.index(True) if True in L else -1
		### if there is a filename and if there is no extention -> its a to disk like object
		disk_model = filename_without_ext_flag >= 0 and not os.path.splitext(args.values()[filename_without_ext_flag])[-1] != ''

		### find if scope is present in class name
		match = [re.match('[-_a-zA-z]*scope[-_a-zA-z]*',s, re.IGNORECASE) for s in clsmbr.keys()+[specific_behavior]]
		scope_model = map(lambda a: a.group(0), filter(lambda s : s is not None, match)) != []

		### find if messagecollector is present in class name
		match = [re.match('[-_a-zA-z]*collector[-_a-zA-z]*',s, re.IGNORECASE) for s in clsmbr.keys()+[specific_behavior]]
		messagecollector_model = map(lambda a: a.group(0), filter(lambda s : s is not None, match)) != []

		# new codeBlcok instance
		if disk_model or messagecollector_model:
			m = DiskGUI(label)
		elif scope_model:
			m = ScopeGUI(label)
		else:
			m = CodeBlock(label)

		# define behavioral args from python class
		m.args = args

		return m