Exemplo n.º 1
0
    def Populate(self, pluginsList):
        """ Populate method must be called just before constructor.
		"""

        if not self.is_populate:
            # all plug_ins file in plug_ins directory and already loaded
            # list of all file (without __init__.py)
            for root, dirs, files in pluginsList:

                ### append the plug-ins directory to sys.path in order to use local importing notation (import...) in plug-in file.
                if root not in sys.path:
                    sys.path.append(root)

                ### dirs must contain python file
                if files != []:
                    for filename in [f for f in files if f == "__init__.py"]:
                        path = os.path.join(root, filename)
                        L = getPYFileListFromInit(
                            path, '.py') + getPYFileListFromInit(path, '.pyc')
                        for basename in L:
                            ### try to add dynamically plug-ins
                            #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
Exemplo n.º 2
0
    def GetPYFileList(dName, ext=".py"):
        """ Return .py files that are instanciable. 
		"""

        ### import are here because the simulator (PyDEVS or PyPDEVS) require it
        from DomainInterface.DomainBehavior import DomainBehavior

        try:
            name_list = getPYFileListFromInit(
                os.path.join(dName, '__init__.py'), ext)
            py_file_list = []

            for s in name_list:
                python_file = os.path.join(dName, s + ext)
                ### 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 = 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):
                            py_file_list.append(s)
                        else:
                            sys.stderr.write(
                                _("%s not imported: Class is not DomainBehavior\n"
                                  % (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 as info:
            py_file_list = []
            # if dName contains a python file, __init__.py is forced
            for f in os.listdir(dName):
                if f.endswith(ext):
                    sys.stderr.write(
                        _("Exception, %s not imported: %s \n" % (dName, info)))
                    break

        return py_file_list
Exemplo n.º 3
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 = getPYFileListFromInit(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