Example #1
0
 def setTimePrint(self, msg):
     """
   Allows the code to toggle timestamp printing.
   @ In, msg, string, the string that means true or false
   @ Out, None
 """
     if utils.stringIsTrue(msg):
         self.callerLength = 40
         self.tagLength = 30
         self.printTime = True
     elif utils.stringIsFalse(msg):
         self.callerLength = 25
         self.tagLength = 15
         self.printTime = False
Example #2
0
 def convert(cls, value):
     """
   Converts value from string to a bool.
   @ In, value, string, the value to convert
   @ Out, convert, bool, the converted value
 """
     if utils.stringIsTrue(value):
         return True
     elif utils.stringIsFalse(value):
         return False
     else:
         raise IOError(
             'Unrecognized boolean value: "{}"! Expected one of {}'.format(
                 value, utils.boolThingsFull))
Example #3
0
 def _readMoreXML(self,xmlNode):
   """
     Function to read the portion of the xml input that belongs to this specialized class
     and initialize some stuff based on the inputs got
     @ In, xmlNode, xml.etree.ElementTree.Element, Xml element node
     @ Out, None
   """
   Model._readMoreXML(self, xmlNode)
   paramInput = Code.getInputSpecification()()
   paramInput.parseNode(xmlNode)
   self.clargs={'text':'', 'input':{'noarg':[]}, 'pre':'', 'post':''} #output:''
   self.fargs={'input':{}, 'output':'', 'moosevpp':''}
   for child in paramInput.subparts:
     if child.getName() =='executable':
       self.executable = child.value if child.value is not None else ''
     if child.getName() =='walltime':
       self.maxWallTime = child.value
     if child.getName() =='preexec':
       self.preExec = child.value
     elif child.getName() == 'clargs':
       argtype    = child.parameterValues['type']      if 'type'      in child.parameterValues else None
       arg        = child.parameterValues['arg']       if 'arg'       in child.parameterValues else None
       ext        = child.parameterValues['extension'] if 'extension' in child.parameterValues else None
       # The default delimiter is one empty space
       delimiter  = child.parameterValues['delimiter'] if 'delimiter' in child.parameterValues else ' '
       if argtype == None:
         self.raiseAnError(IOError,'"type" for clarg not specified!')
       elif argtype == 'text':
         if ext != None:
           self.raiseAWarning('"text" nodes only accept "type" and "arg" attributes! Ignoring "extension"...')
         if not delimiter.strip():
           self.raiseAWarning('"text" nodes only accept "type" and "arg" attributes! Ignoring "delimiter"...')
         if arg == None:
           self.raiseAnError(IOError,'"arg" for clarg '+argtype+' not specified! Enter text to be used.')
         self.clargs['text']=arg
       elif argtype == 'input':
         if ext == None:
           self.raiseAnError(IOError,'"extension" for clarg '+argtype+' not specified! Enter filetype to be listed for this flag.')
         if arg == None:
           self.clargs['input']['noarg'].append((ext,delimiter))
         else:
           if arg not in self.clargs['input'].keys():
             self.clargs['input'][arg]=[]
           # The delimiter is used to link 'arg' with the input file that have the file extension
           # given by 'extension'. In general, empty space is used. But in some specific cases, the codes may require
           # some specific delimiters to link the 'arg' and input files
           self.clargs['input'][arg].append((ext,delimiter))
       elif argtype == 'output':
         if arg == None:
           self.raiseAnError(IOError,'"arg" for clarg '+argtype+' not specified! Enter flag for output file specification.')
         self.clargs['output'] = arg
       elif argtype == 'prepend':
         if ext != None:
           self.raiseAWarning('"prepend" nodes only accept "type" and "arg" attributes! Ignoring "extension"...')
         if arg == None:
           self.raiseAnError(IOError,'"arg" for clarg '+argtype+' not specified! Enter text to be used.')
         if 'pre' in self.clargs:
           self.clargs['pre'] = arg+' '+self.clargs['pre']
         else:
           self.clargs['pre'] = arg
       elif argtype == 'python':
         pythonName = utils.getPythonCommand()
         if 'pre' in self.clargs:
           self.clargs['pre'] = self.clargs['pre']+' '+pythonName
         else:
           self.clargs['pre'] = pythonName
       elif argtype == 'postpend':
         if ext != None:
           self.raiseAWarning('"postpend" nodes only accept "type" and "arg" attributes! Ignoring "extension"...')
         if arg == None:
           self.raiseAnError(IOError,'"arg" for clarg '+argtype+' not specified! Enter text to be used.')
         self.clargs['post'] = arg
       else:
         self.raiseAnError(IOError,'clarg type '+argtype+' not recognized!')
     elif child.getName() == 'fileargs':
       argtype = child.parameterValues['type']      if 'type'      in child.parameterValues else None
       arg     = child.parameterValues['arg']       if 'arg'       in child.parameterValues else None
       ext     = child.parameterValues['extension'] if 'extension' in child.parameterValues else None
       if argtype == None:
         self.raiseAnError(IOError,'"type" for filearg not specified!')
       elif argtype == 'input':
         if arg == None:
           self.raiseAnError(IOError,'filearg type "input" requires the template variable be specified in "arg" attribute!')
         if ext == None:
           self.raiseAnError(IOError,'filearg type "input" requires the auxiliary file extension be specified in "ext" attribute!')
         self.fargs['input'][arg]=[ext]
       elif argtype == 'output':
         if self.fargs['output']!='':
           self.raiseAnError(IOError,'output fileargs already specified!  You can only specify one output fileargs node.')
         if arg == None:
           self.raiseAnError(IOError,'filearg type "output" requires the template variable be specified in "arg" attribute!')
         self.fargs['output']=arg
       elif argtype.lower() == 'moosevpp':
         if self.fargs['moosevpp'] != '':
           self.raiseAnError(IOError,'moosevpp fileargs already specified!  You can only specify one moosevpp fileargs node.')
         if arg == None:
           self.raiseAnError(IOError,'filearg type "moosevpp" requires the template variable be specified in "arg" attribute!')
         self.fargs['moosevpp']=arg
       else:
         self.raiseAnError(IOError,'filearg type '+argtype+' not recognized!')
   if self.executable == '':
     self.raiseAWarning('The node "<executable>" was not found in the body of the code model '+str(self.name)+' so no code will be run...')
   else:
     if utils.stringIsFalse(os.environ.get('RAVENinterfaceCheck','False')):
       if '~' in self.executable:
         self.executable = os.path.expanduser(self.executable)
       abspath = os.path.abspath(str(self.executable))
       if os.path.exists(abspath):
         self.executable = abspath
       else:
         self.raiseAMessage('not found executable '+self.executable,'ExceptedError')
     else:
       self.foundExecutable = False
       self.raiseAMessage('InterfaceCheck: ignored executable '+self.executable, 'ExceptedError')
   if self.preExec is not None:
     if '~' in self.preExec:
       self.preExec = os.path.expanduser(self.preExec)
     abspath = os.path.abspath(self.preExec)
     if os.path.exists(abspath):
       self.preExec = abspath
     else:
       self.foundPreExec = False
       self.raiseAMessage('not found preexec '+self.preExec,'ExceptedError')
   self.code = Code.CodeInterfaces.returnCodeInterface(self.subType, self)
   self.code.readMoreXML(xmlNode, self._ravenWorkingDir) #TODO figure out how to handle this with InputData
   self.code.setInputExtension(list(a[0].strip('.') for b in (c for c in self.clargs['input'].values()) for a in b))
   self.code.addInputExtension(list(a.strip('.') for b in (c for c in self.fargs ['input'].values()) for a in b))
   self.code.addDefaultExtension()
Example #4
0
 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 utils.stringIsFalse(text):
                 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 element.text is None:
                 self.raiseAnError(
                     IOError,
                     'RunInfo.WorkingDir is empty! Use "." to signify "work here" or specify a directory.'
                 )
             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 utils.stringIsTrue(element.text):
                 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!')