Beispiel #1
0
    def Populate(self, pluginsList):
        """ Populate method must be called just before construtor.
		"""
        if not self.is_populate:
            # all plugins file in plugins directory and already loaded
            # list of all file (without __init__.py)
            for root, dirs, files in pluginsList:
                ### dirs must contain python file
                if files:
                    #for filename in filter(lambda f: not f.startswith('__') and f.endswith('.py'), files):
                    for filename in filter(lambda f: f == "__init__.py",
                                           files):
                        for basename in Utilities.getFileListFromInit(
                                os.path.join(root, filename)):
                            ### try to add dynamicaly pulgins
                            #try:
                            #t = threading.Thread(target=self.Importing, args=(root, basename,))
                            #t.start()
                            #except Exception:
                            #if wx.Platform == '__WXGTK__':
                            ##i+=1
                            #wx.CallLater(500, self.Importing, root, basename,)
                            #else:
                            self.Importing(root, basename)

            self.is_populate = True
Beispiel #2
0
    def DocDirectory(self, path):
        """ Return doc of all modules composing path directory by reading its __ini__.py
		"""
        ### init_file at first level !
        init_file = os.path.join(path, '__init__.py')

        doc = ""
        ### if init_file exists in module
        if os.path.exists(init_file):
            ### get list of content filename
            lst = Utilities.getFileListFromInit(init_file)
            if lst:
                # for each python filename, inspect its module info
                for fn in lst:
                    fn_path = os.path.join(path, fn + '.py')
                    t = inspect.getmoduleinfo(fn_path)
                    if t is not None:
                        name, suffix, mode, module_type = t
                        doc += _("---------- %s module :\n") % fn + \
                            _("\tname : %s\n") % name + \
                            _("\tsuffix : %s\n") % suffix + \
                            _("\tmode : %s\n") % mode + \
                            _("\ttype of module : %s\n") % module_type + \
                            _("\tpath : %s\n\n") % fn_path
                    else:
                        doc += _(
                            "----------%s module not inspectable !\n") % fn
            #else:
            #pass
            #doc += _("%s is empty !\n")%init_file
        #else:
        #pass
        #doc += _("%s dont exist !\n")%init_file

        ### TODO take in charge also amd and cmd !

        return doc
	def Populate(self, pluginsList):
		""" Populate method must be called just before construtor.
		"""
		if not self.is_populate:
			# all plugins file in plugins directory and already loaded
			# list of all file (without __init__.py)
			for root, dirs, files in pluginsList:
				### dirs must contain python file
				if files:
					#for filename in filter(lambda f: not f.startswith('__') and f.endswith('.py'), files):
					for filename in filter(lambda f: f == "__init__.py", files):
						for basename in Utilities.getFileListFromInit(os.path.join(root,filename)):
							### try to add dynamicaly pulgins
							#try:
								#t = threading.Thread(target=self.Importing, args=(root, basename,))
								#t.start()
							#except Exception:
								#if wx.Platform == '__WXGTK__':
									##i+=1
									#wx.CallLater(500, self.Importing, root, basename,)
								#else:
								self.Importing(root, basename)
											
			self.is_populate = True
	def DocDirectory(self, path):
		""" Return doc of all modules composing path directory by reading its __ini__.py
		"""
		### init_file at first level !
		init_file = os.path.join(path, '__init__.py')

		doc = ""
		### if init_file exists in module
		if os.path.exists(init_file):
			### get list of content filename
			lst = Utilities.getFileListFromInit(init_file)
			if lst:
				# for each python filename, inspect its module info
				for fn in lst:
					fn_path = os.path.join(path, fn + '.py')
					t = inspect.getmoduleinfo(fn_path)
					if t is not None:
						name, suffix, mode, module_type = t
						doc += _("---------- %s module :\n") % fn + \
							   _("\tname : %s\n") % name + \
							   _("\tsuffix : %s\n") % suffix + \
							   _("\tmode : %s\n") % mode + \
							   _("\ttype of module : %s\n") % module_type + \
							   _("\tpath : %s\n\n") % fn_path
					else:
						doc += _("----------%s module not inspectable !\n") % fn
			#else:
				#pass
				#doc += _("%s is empty !\n")%init_file
		#else:
			#pass
			#doc += _("%s dont exist !\n")%init_file

					### TODO take in charge also amd and cmd !

		return doc
Beispiel #5
0
    def GetModelList(self, dName):
        """ Get the list of files from dName directory.
		"""

        ### list of py file from __init__.py
        if LibraryTree.EXT_LIB_PYTHON_FLAG:

            ### lsit of py file from url
            if dName.startswith('http'):

                o = urlparse(dName)
                c = httplib.HTTPConnection(o.netloc)
                c.request('GET', o.path + '/__init__.py')

                r = c.getresponse()
                code = r.read()

                if r.status == 200:
                    exec code
                    tmp = filter(
                        lambda s: s.replace('\n', '').replace('\t', '').
                        replace(',', '').replace('"', "").replace(
                            '\'', "").strip(), __all__)
                    ### test if the content of __init__.py file is python file (isfile equivalent)
                    py_file_list = [
                        s for s in tmp
                        if 'python' in urllib.urlopen(dName + '/' + s +
                                                      '.py').info().type
                    ]

                else:
                    py_file_list = []

                return py_file_list
            else:
                try:
                    name_list = Utilities.getFileListFromInit(
                        os.path.join(dName, '__init__.py'))
                    py_file_list = []
                    for s in name_list:
                        python_file = os.path.join(dName, s + '.py')
                        ### test if tmp is only composed by python file (case of the user write into the __init__.py file directory name is possible ! then we delete the directory names)
                        if os.path.isfile(python_file):

                            cls = Components.GetClass(python_file)

                            if cls is not None and not isinstance(cls, tuple):
                                ### only model that herite from DomainBehavior is shown in lib
                                if issubclass(cls,
                                              DomainBehavior.DomainBehavior):
                                    py_file_list.append(s)

                            ### If cls is tuple, there is an error but we load the model to correct it.
                            ### If its not DEVS model, the Dnd don't allows the instantiation and when the error is corrected, it don't appear before a update.
                            else:

                                py_file_list.append(s)

                except Exception:
                    py_file_list = []
                    # if dName contains a python file, __init__.py is forced
                    for f in os.listdir(dName):
                        if f.endswith('.py'):
                            #sys.stderr.write(_("%s not imported : %s \n"%(dName,info)))
                            break
        else:
            py_file_list = []

        # list of amd and cmd files
        devsimpy_file_list = [
            f for f in os.listdir(dName)
            if os.path.isfile(os.path.join(dName, f)) and (f[:2] != '__') and (
                f.endswith(LibraryTree.EXT_LIB_FILE))
        ]

        return py_file_list + devsimpy_file_list