def __processFiles(self, path, spacecraft, procpath, collection, checkLoadable=True): if not os.path.isdir(path): LOG("Discarding file: " + path) return if not path in sys.path: LOG("Append python path: " + path) sys.path.append(path) filelist = os.listdir(path) for procfile in filelist: thefile = os.path.splitext(procfile) if thefile[1] == '.py' and thefile[0] != "__init__": try: self.__parser.parseFile(path + os.sep + procfile) except ParseError, e: LOG(e.message + ": " + procfile) continue except NotLoadable, e: LOG(e.message + ": " + procfile) continue fullpath = path + os.sep + procfile procId = fullpath.split(procpath)[1][1:][:-3] theProcedure = Procedure(procId, self.__parser.properties(), fullpath) if self.__isDomainApplicable(theProcedure, spacecraft): collection[procId] = theProcedure self.__filenameToId[fullpath] = procId procName = theProcedure.name() id = procId + "|" + procName if checkLoadable and theProcedure.isLoadable()\ and not id in self.__loadableProcedures: self.__loadableProcedures.append(id) else: LOG("Discarding procedure: " + procId)
def __processFiles(self, path, spacecraft, procpath, collection, checkLoadable = True ): if not os.path.isdir(path): LOG("Discarding file: " + path) return if not path in sys.path: LOG("Append python path: " + path) sys.path.append( path ) filelist = os.listdir(path) for procfile in filelist: thefile = os.path.splitext(procfile) if thefile[1] == '.py' and thefile[0] != "__init__": try: self.__parser.parseFile( path + os.sep + procfile) except ParseError,e: LOG(e.message + ": " + procfile) continue except NotLoadable,e: LOG(e.message + ": " + procfile) continue fullpath = path + os.sep + procfile procId = fullpath.split( procpath )[1][1:][:-3] theProcedure = Procedure(procId, self.__parser.properties(), fullpath) if self.__isDomainApplicable(theProcedure, spacecraft): collection[procId] = theProcedure self.__filenameToId[fullpath] = procId procName = theProcedure.name() id = procId + "|" + procName if checkLoadable and theProcedure.isLoadable()\ and not id in self.__loadableProcedures: self.__loadableProcedures.append(id) else: LOG("Discarding procedure: " + procId)
continue except: LOG("Unable to read file: " + procfile, LOG_ERROR) continue fullpath = path + os.sep + procfile procId = fullpath.split(procpath)[1][1:][:-3] theProcedure = Procedure(procId, self.__parser.properties(), fullpath) if self.__isDomainApplicable(theProcedure, spacecraft): collection[procId] = theProcedure self.__filenameToId[fullpath] = procId procName = theProcedure.name() id = procId + "|" + procName if checkLoadable and theProcedure.isLoadable()\ and not id in self.__loadableProcedures: self.__loadableProcedures.append(id) else: LOG("Discarding procedure: " + procId) elif thefile[1] == '.pyc': os.remove(path + os.sep + procfile) elif thefile[1] == '': self.__processFiles(path + os.sep + thefile[0], spacecraft, procpath, collection, checkLoadable) #========================================================================== def __isDomainApplicable(self, procedureObject, spacecraft): spacecraft = spacecraft.strip() if spacecraft == "STD": return True try:
LOG(e.message + ": " + procfile) continue except: LOG("Unable to read file: " + procfile, LOG_ERROR) continue fullpath = path + os.sep + procfile procId = fullpath.split( procpath )[1][1:][:-3] theProcedure = Procedure(procId, self.__parser.properties(), fullpath) if self.__isDomainApplicable(theProcedure, spacecraft): collection[procId] = theProcedure self.__filenameToId[fullpath] = procId procName = theProcedure.name() id = procId + "|" + procName if checkLoadable and theProcedure.isLoadable()\ and not id in self.__loadableProcedures: self.__loadableProcedures.append(id) else: LOG("Discarding procedure: " + procId) elif thefile[1]=='.pyc': os.remove(path + os.sep + procfile) elif thefile[1]=='': self.__processFiles( path + os.sep + thefile[0], spacecraft, procpath, collection, checkLoadable) #========================================================================== def __isDomainApplicable(self, procedureObject, spacecraft ): spacecraft = spacecraft.strip() if spacecraft == "STD": return True try: scList = procedureObject.getSpacecraft()