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 filter(lambda f: not f.startswith('__') and f.endswith('.py'), files): for filename in filter(lambda f: f == "__init__.py", files): for basename in getFileListFromInit(os.path.join(root,filename)): ### 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
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 = 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 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 = 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 GetModelList(self, dName): """ Get the list of files from dName directory. """ ### import are here because the simulator (PyDEVS or PyPDEVS) require it from DomainInterface.DomainBehavior import DomainBehavior ### list of py file from __init__.py if LibraryTree.EXT_LIB_PYTHON_FLAG: ### list 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 urlopen(dName+'/'+s+'.py').info().type] else: py_file_list = [] return py_file_list else: try: name_list = 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 = 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, info: 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
def GetModelList(self, dName): """ Get the list of files from dName directory. """ ### import are here because the simulator (PyDEVS or PyPDEVS) require it from DomainInterface.DomainBehavior import DomainBehavior ### list of py file from __init__.py if LibraryTree.EXT_LIB_PYTHON_FLAG: ### list 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 urlopen(dName + '/' + s + '.py').info().type ] else: py_file_list = [] return py_file_list else: try: name_list = 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 = 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, info: 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