def _readMoreXML(self, xmlNode): """ Function to read the portion of the xml input that belongs to this specialized class and initialize variables based on the input received. @ In, xmlNode, xml.etree.ElementTree.Element, XML element node that represents the portion of the input that belongs to this class @ Out, None """ DateBase._readMoreXML(self, xmlNode) # Check if database directory exist, otherwise create it if '~' in self.databaseDir: self.databaseDir = copy.copy(os.path.expanduser(self.databaseDir)) # Determine RELATIVE location for HDF5. # - if a full path is given, accept it as given, else ... if not os.path.isabs(self.databaseDir): # use working dir as base self.databaseDir = os.path.join(self.workingDir, self.databaseDir) self.databaseDir = os.path.normpath(self.databaseDir) utils.makeDir(self.databaseDir) self.raiseADebug('Database Directory is:', self.databaseDir) # Check if a filename has been provided # if yes, we assume the user wants to load the data from there # or update it #try: self.filename = xmlNode.attrib.get('filename', self.name + '.h5') if 'readMode' not in xmlNode.attrib.keys(): self.raiseAnError( IOError, 'No "readMode" attribute was specified for hdf5 database', self.name) self.readMode = xmlNode.attrib['readMode'].strip().lower() readModes = ['read', 'overwrite'] if self.readMode not in readModes: self.raiseAnError(IOError, 'readMode attribute for hdf5 database', self.name, 'is not recognized:', self.readMode, '. Options are:', readModes) self.raiseADebug('HDF5 Read Mode is "' + self.readMode + '".') fullpath = os.path.join(self.databaseDir, self.filename) if os.path.isfile(fullpath): if self.readMode == 'read': self.exist = True elif self.readMode == 'overwrite': self.exist = False self.database = h5Data(self.name, self.databaseDir, self.messageHandler, self.filename, self.exist) else: #file does not exist in path if self.readMode == 'read': self.raiseAWarning( 'Requested to read from database, but it does not exist at:', fullpath, '; continuing without reading...') self.exist = False self.database = h5Data(self.name, self.databaseDir, self.messageHandler, self.filename, self.exist) self.raiseAMessage('Database is located at:', fullpath)
def __readRunInfo(self,xmlNode,runInfoSkip,xmlFilename): """ Method that reads the xml input file for the RunInfo block @ In, xmlNode, xml.etree.Element, the xml node that belongs to Simulation @ In, runInfoSkip, string, the runInfo step to skip @ In, xmlFilename, string, xml input file name @ Out, None """ if 'verbosity' in xmlNode.attrib.keys(): self.verbosity = xmlNode.attrib['verbosity'] self.raiseAMessage('Global verbosity level is "',self.verbosity,'"',verbosity='quiet') for element in xmlNode: if element.tag in runInfoSkip: self.raiseAWarning("Skipped element ",element.tag) elif element.tag == 'printInput': text = element.text.strip() if element.text is not None else '' #extension fixing if len(text) >= 4 and text[-4:].lower() == '.xml': text = text[:-4] # if the user asked to not print input instead of leaving off tag, respect it if text.lower() in utils.stringsThatMeanFalse(): self.runInfoDict['printInput'] = False # if the user didn't provide a name, provide a default elif len(text)<1: self.runInfoDict['printInput'] = 'duplicated_input.xml' # otherwise, use the user-provided name else: self.runInfoDict['printInput'] = text+'.xml' elif element.tag == 'WorkingDir': # first store the cwd, the "CallDir" self.runInfoDict['CallDir'] = os.getcwd() # then get the requested "WorkingDir" tempName = element.text if '~' in tempName: tempName = os.path.expanduser(tempName) if os.path.isabs(tempName): self.runInfoDict['WorkingDir'] = tempName elif "runRelative" in element.attrib: self.runInfoDict['WorkingDir'] = os.path.abspath(tempName) else: if xmlFilename == None: self.raiseAnError(IOError,'Relative working directory requested but xmlFilename is None.') # store location of the input xmlDirectory = os.path.dirname(os.path.abspath(xmlFilename)) self.runInfoDict['InputDir'] = xmlDirectory rawRelativeWorkingDir = element.text.strip() # working dir is file location + relative working dir self.runInfoDict['WorkingDir'] = os.path.join(xmlDirectory,rawRelativeWorkingDir) utils.makeDir(self.runInfoDict['WorkingDir']) elif element.tag == 'maxQueueSize': try: self.runInfoDict['maxQueueSize'] = int(element.text) except ValueError: self.raiseAnError('Value give for RunInfo.maxQueueSize could not be converted to integer: {}'.format(element.text)) elif element.tag == 'RemoteRunCommand': tempName = element.text if '~' in tempName: tempName = os.path.expanduser(tempName) if os.path.isabs(tempName): self.runInfoDict['RemoteRunCommand'] = tempName else: self.runInfoDict['RemoteRunCommand'] = os.path.abspath(os.path.join(self.runInfoDict['FrameworkDir'],tempName)) elif element.tag == 'NodeParameter': self.runInfoDict['NodeParameter'] = element.text.strip() elif element.tag == 'MPIExec': self.runInfoDict['MPIExec'] = element.text.strip() elif element.tag == 'JobName': self.runInfoDict['JobName' ] = element.text.strip() elif element.tag == 'ParallelCommand': self.runInfoDict['ParallelCommand' ] = element.text.strip() elif element.tag == 'queueingSoftware': self.runInfoDict['queueingSoftware' ] = element.text.strip() elif element.tag == 'ThreadingCommand': self.runInfoDict['ThreadingCommand' ] = element.text.strip() elif element.tag == 'NumThreads': self.runInfoDict['NumThreads' ] = int(element.text) elif element.tag == 'totalNumCoresUsed': self.runInfoDict['totalNumCoresUsed' ] = int(element.text) elif element.tag == 'NumMPI': self.runInfoDict['NumMPI' ] = int(element.text) elif element.tag == 'internalParallel': self.runInfoDict['internalParallel' ] = utils.interpretBoolean(element.text) elif element.tag == 'batchSize': self.runInfoDict['batchSize' ] = int(element.text) elif element.tag.lower() == 'maxqueuesize': self.runInfoDict['maxQueueSize' ] = int(element.text) elif element.tag == 'MaxLogFileSize': self.runInfoDict['MaxLogFileSize' ] = int(element.text) elif element.tag == 'precommand': self.runInfoDict['precommand' ] = element.text elif element.tag == 'postcommand': self.runInfoDict['postcommand' ] = element.text elif element.tag == 'deleteOutExtension': self.runInfoDict['deleteOutExtension'] = element.text.strip().split(',') elif element.tag == 'delSucLogFiles' : if element.text.lower() in utils.stringsThatMeanTrue(): self.runInfoDict['delSucLogFiles' ] = True else: self.runInfoDict['delSucLogFiles' ] = False elif element.tag == 'logfileBuffer': self.runInfoDict['logfileBuffer'] = utils.convertMultipleToBytes(element.text.lower()) elif element.tag == 'clusterParameters': self.runInfoDict['clusterParameters'].extend(splitCommand(element.text)) #extend to allow adding parameters at different points. elif element.tag == 'mode' : self.runInfoDict['mode'] = element.text.strip().lower() #parallel environment if self.runInfoDict['mode'] in self.__modeHandlerDict: self.__modeHandler = self.__modeHandlerDict[self.runInfoDict['mode']](self.messageHandler) self.__modeHandler.XMLread(element) else: self.raiseAnError(IOError,"Unknown mode "+self.runInfoDict['mode']) elif element.tag == 'expectedTime': self.runInfoDict['expectedTime' ] = element.text.strip() elif element.tag == 'Sequence': for stepName in element.text.split(','): self.stepSequenceList.append(stepName.strip()) elif element.tag == 'DefaultInputFile': self.runInfoDict['DefaultInputFile'] = element.text.strip() elif element.tag == 'CustomMode' : modeName = element.text.strip() modeClass = element.attrib["class"] modeFile = element.attrib["file"] #XXX This depends on if the working directory has been set yet. # So switching the order of WorkingDir and CustomMode can # cause different results. modeFile = modeFile.replace("%BASE_WORKING_DIR%",self.runInfoDict['WorkingDir']) modeFile = modeFile.replace("%FRAMEWORK_DIR%",self.runInfoDict['FrameworkDir']) modeDir, modeFilename = os.path.split(modeFile) if modeFilename.endswith(".py"): modeModulename = modeFilename[:-3] else: modeModulename = modeFilename os.sys.path.append(modeDir) module = __import__(modeModulename) if modeName in self.__modeHandlerDict: self.raiseAWarning("duplicate mode definition " + modeName) self.__modeHandlerDict[modeName] = module.__dict__[modeClass] else: self.raiseAnError(IOError,'RunInfo element "'+element.tag +'" unknown!')