コード例 #1
0
ファイル: MOOSEparser.py プロジェクト: waynemorrison/raven
 def printInput(self,outfile=None):
   """
     Method to print out the new input
     @ In, outfile, string, optional, output file root
     @ Out, None
   """
   # 4 sub levels maximum
   def printSubLevels(xmlnode,IOfile,indentMultiplier):
     IOfile.write(b'  '*indentMultiplier+b'[./'+toBytes(xmlnode.tag)+b']\n')
     for string in xmlnode.tail if xmlnode.tail else []:
       IOfile.write(b'    '*indentMultiplier+string+b'\n')
     for key in xmlnode.attrib.keys():
       IOfile.write(b'    '*indentMultiplier+toBytes(key)+b' = '+toBytes(toStrish(xmlnode.attrib[key]))+b'\n')
   if outfile==None:
     outfile =self.inputfile
   IOfile = open(outfile,'wb')
   for child in self.root:
     IOfile.write(b'['+toBytes(child.tag)+b']\n')
     if child.tail:
       for string in child.tail:
         IOfile.write(b'  '+string+b'\n')
     for key in child.attrib.keys():
       IOfile.write(b'  '+toBytes(key)+b' = '+toBytes(toStrish(child.attrib[key]))+b'\n')
     for childChild in child:
       printSubLevels(childChild,IOfile,1)
       for childChildChild in childChild:
         printSubLevels(childChildChild,IOfile,2)
         for childChildChildChild in childChildChild:
           printSubLevels(childChildChildChild,IOfile,3)
           IOfile.write(b'      [../]\n')
         IOfile.write(b'    [../]\n')
       IOfile.write(b'  [../]\n')
     IOfile.write(b'[]\n')
コード例 #2
0
 def printSubLevels(xmlnode, IOfile, indentMultiplier):
     IOfile.write('  ' * indentMultiplier + '[./' + xmlnode.tag + ']\n')
     for string in xmlnode.tail if xmlnode.tail else []:
         IOfile.write('    ' * indentMultiplier + string + '\n')
     for key in xmlnode.attrib.keys():
         IOfile.write('    ' * indentMultiplier + key + ' = ' +
                      toStrish(xmlnode.attrib[key]) + '\n')
コード例 #3
0
 def printSubLevels(xmlnode, IOfile, indentMultiplier):
     IOfile.write(b'  ' * indentMultiplier + b'[./' +
                  toBytes(xmlnode.tag) + b']\n')
     for string in xmlnode.tail if xmlnode.tail else []:
         IOfile.write(b'    ' * indentMultiplier + string + b'\n')
     for key in xmlnode.attrib.keys():
         IOfile.write(b'    ' * indentMultiplier + toBytes(key) +
                      b' = ' + toBytes(toStrish(xmlnode.attrib[key])) +
                      b'\n')
コード例 #4
0
   def write(IOfile, indent, xmlnode):
       """
   Method to print out the key and value pairs
  @ In, IOfile, file, the file to write to
  @ In, indent, string, the string to print before the key
  @ In, xmlnode, ElementNode, the node with the attributes
  @ Out, None
 """
       for key in sorted(xmlnode.attrib.keys()):
           value = xmlnode.attrib[key]
           if type(value) == float:
               valueStr = repr(value)
           else:
               valueStr = toStrish(value)
           IOfile.write(indent + toString(key) + ' = ' + valueStr + '\n')