예제 #1
0
 def ExternalXMLread(self,externalXMLFile,externalXMLNode,xmlFileName=None):
   """
     parses the external xml input file
     @ In, externalXMLFile, string, the filename for the external xml file that will be loaded
     @ In, externalXMLNode, string, decribes which node will be loaded to raven input file
     @ In, xmlFileName, string, optional, the raven input file name
     @ Out, externalElemment, xml.etree.ElementTree.Element, object that will be added to the current tree of raven input
   """
   #TODO make one for getpot too
   if '~' in externalXMLFile:
     externalXMLFile = os.path.expanduser(externalXMLFile)
   if not os.path.isabs(externalXMLFile):
     if xmlFileName == None:
       self.raiseAnError(IOError,'Relative working directory requested but input xmlFileName is None.')
     xmlDirectory = os.path.dirname(os.path.abspath(xmlFileName))
     externalXMLFile = os.path.join(xmlDirectory,externalXMLFile)
   if os.path.exists(externalXMLFile):
     externalTree = TreeStructure.parse(externalXMLFile)
     externalElement = externalTree.getroot()
     if externalElement.tag != externalXMLNode:
       self.raiseAnError(IOError,'The required node is: ' + externalXMLNode + 'is different from the provided external xml type: ' + externalElement.tag)
   else:
     self.raiseAnError(IOError,'The external xml input file ' + externalXMLFile + ' does not exist!')
   return externalElement
예제 #2
0
파일: testParse.py 프로젝트: since801/raven
        #both are done
        return same,msg
    try:
      bl = next(genB)
    except StopIteration:
      return False,msg + ['file '+str(a)+' has more lines than '+str(b)]
    if al.rstrip('\n\r') != bl.rstrip('\n\r'):
      same = False
      print('al '+repr(al)+" != bl "+repr(bl))
      msg += ['line '+str(i)+' is not the same!']



#first test XML to XML
print('Testing XML to XML ...')
tree = TS.parse(open(os.path.join('parse','example_xml.xml'),'r'))
strTree = TS.tostring(tree)
fname = os.path.join('parse','fromXmltoXML.xml')
open(fname,'w').write(toString(strTree))
same,msg = checkSameFile(open(fname,'r'),open(os.path.join('gold',fname),'r'))
if same:
  results['passed']+=1
  print('  ... passed!')
else:
  results['failed']+=1
  print('  ... failures in XML to XML:')
  print('     ',msg[0])



getpot = open(os.path.join('parse','example_getpot.i'),'r')
예제 #3
0
파일: Driver.py 프로젝트: HCBINL/raven
        inputFiles = [simulation.getDefaultInputFile()]
    else:
        inputFiles = sys.argv[1:]

    for i in range(len(inputFiles)):
        if not os.path.isabs(inputFiles[i]):
            inputFiles[i] = os.path.join(workingDir, inputFiles[i])

    simulation.setInputFiles(inputFiles)
    #Parse the input
    #For future developers of this block, assure that useful, informative exceptions
    #  are still thrown while parsing the XML tree.  Otherwise any error made by
    #  the developer or user might be obfuscated.
    for inputFile in inputFiles:
        try:
            tree = TS.parse(open(inputFile, 'r'))
        except TS.InputParsingError as e:
            print('\nInput Parsing error!', e, '\n')
            sys.exit(1)

        #except?  riseanIOError('not possible to parse (xml based) the input file '+inputFile)
        if verbosity == 'debug':
            print('DRIVER', 'opened file ' + inputFile)

        root = tree.getroot()
        if root.tag != 'Simulation':
            e = IOError('The outermost block of the input file ' + inputFile +
                        ' it is not Simulation')
            print('\nInput XML Error!', e, '\n')
            sys.exit(1)
예제 #4
0
    inputFiles = [simulation.getDefaultInputFile()]
  else:
    inputFiles = sys.argv[1:]

  for i in range(len(inputFiles)):
    if not os.path.isabs(inputFiles[i]):
      inputFiles[i] = os.path.join(workingDir,inputFiles[i])

  simulation.setInputFiles(inputFiles)
  #Parse the input
  #For future developers of this block, assure that useful, informative exceptions
  #  are still thrown while parsing the XML tree.  Otherwise any error made by
  #  the developer or user might be obfuscated.
  for inputFile in inputFiles:
    try:
      tree = TS.parse(file(inputFile,'r'))
    except TS.InputParsingError as e:
      print('\nInput Parsing error!',e,'\n')
      sys.exit(1)

    #except?  riseanIOError('not possible to parse (xml based) the input file '+inputFile)
    if verbosity=='debug':
      print('DRIVER','opened file '+inputFile)

    root = tree.getroot()
    if root.tag != 'Simulation':
      e=IOError('The outermost block of the input file '+inputFile+' it is not Simulation')
      print('\nInput XML Error!',e,'\n')
      sys.exit(1)

    # call the function to load the external xml files into the input tree
예제 #5
0
                return same, msg
        try:
            bl = next(genB)
        except StopIteration:
            return False, msg + [
                'file ' + str(a) + ' has more lines than ' + str(b)
            ]
        if al.rstrip('\n\r') != bl.rstrip('\n\r'):
            same = False
            print('al ' + repr(al) + " != bl " + repr(bl))
            msg += ['line ' + str(i) + ' is not the same!']


#first test XML to XML
print('Testing XML to XML ...')
tree = TS.parse(open(os.path.join('parse', 'example_xml.xml'), 'r'))
strTree = TS.tostring(tree)
fname = os.path.join('parse', 'fromXmltoXML.xml')
open(fname, 'w').write(toString(strTree))
same, msg = checkSameFile(open(fname, 'r'),
                          open(os.path.join('gold', fname), 'r'))
if same:
    results['passed'] += 1
    print('  ... passed!')
else:
    results['failed'] += 1
    print('  ... failures in XML to XML:')
    print('     ', msg[0])

print('Results:', list('%s: %i' % (k, v) for k, v in results.items()))
sys.exit(results['failed'])