Classes | |
class | Constituent |
class | Material |
Functions | |
def | getTwiki |
def | main |
def | parseComment |
def | parseInFile |
def | readConfig |
def | readMaterialFile |
def | readSection |
def twikiExport::getTwiki | ( | materials, | |
config | |||
) |
Definition at line 126 of file twikiExport.py.
00127 : 00128 result = config["twiki"]["pagename"]+"\n" 00129 result += "%TOC%\n\n" 00130 for mat in materials: 00131 result += config["twiki"]["heading"]+mat.theName+"\n" 00132 result += "short Description: *"+mat.theDescription+"* <br>\n" 00133 result += "Mass: %.3fg\n" % mat.getMass() 00134 result += config["twiki"]["tableformat"]+'\n' 00135 result += "| ** | *Volume* | *Density* | *X<sub>0</sub>* | *λ<sub>0</sub>* |\n" 00136 result += "| ** | *cms<sup>3</sup>* | *g cm<sup>-3</sup>* | *cm* | *cm* |\n" 00137 result += "| Real | %(Volume).3f | %(Density).3f | %(X0).3f | %(L0).3f |\n" % mat.getRealValues() 00138 result += "| Simulation | %(Volume).3f | %(Density).3f | %(X0).3f | %(L0).3f |\n" % mat.getSimValues() 00139 result += "\n"+config["twiki"]["subheading"]+"Comments\n" 00140 result += parseComment(mat.theComment) 00141 result += "\n---+++!!Material\n" 00142 result += config["twiki"]["tableformat"]+'\n' 00143 result += " | *Description* | *Material Name* | *Volume* | *Mass* | *Count* | *Type* | *X<sub>0</sub>* | *λ<sub>0</sub>* |\n" 00144 result += ' | ** | ** | *cm<sup>3</sup>* | *g* | ** | ** | *g cm<sup>-2</sup>* | *g cm<sup>-2</sup>* |\n' 00145 for const in mat.theConstituents: 00146 result += " | =%s= | =%s= | %.2e | %.2e | %.2f | %s | %.2f | %.2f |\n" % ( const.theDescription , const.theName , const.theVolume , const.theMass , const.theCount , const.theType , const.theX0 , const.theL0 ) 00147 # result += " | ="+const.theDescription+"= | ="+const.theName+"= | "+str(const.theVolume)+" | "+str(const.theMass)+" | "+str(const.theCount)+" | "+const.theType+" | "+str(const.theX0)+" | "+str(const.theL0)+" |\n" 00148 result += "\n" 00149 00150 return result 00151 #reads mixed_materials.input and pure_materials.input
def twikiExport::main | ( | ) |
Definition at line 182 of file twikiExport.py.
00183 : 00184 optParser = optparse.OptionParser() 00185 optParser.add_option("-i", "--input", dest="inFile", 00186 help="the .in material description that is the input", metavar="INPUT") 00187 optParser.add_option("-o", "--output", dest="output", 00188 help="the file to put the twiki formated output in (default: <.in-Filename>.twiki)", metavar="TWIKIOUT") 00189 optParser.add_option("-c", "--config", dest="config", 00190 help="configuration to use (default twikiConfig.ini)", metavar="CONFIG") 00191 00192 (options, args) = optParser.parse_args() 00193 00194 if options.inFile == None: 00195 raise StandardError, "no .in File given!" 00196 if options.output == None: 00197 options.output = options.inFile.replace(".in",".twiki") 00198 if options.config == None: 00199 options.config = "twikiConfig.ini" 00200 00201 config = readConfig(options.config) 00202 00203 predefinedMaterials = {} 00204 predefinedMaterials.update( readMaterialFile("pure_materials.input") ) 00205 predefinedMaterials.update( readMaterialFile("mixed_materials.input") ) 00206 00207 inFile = open(options.inFile,"r") 00208 inFileContent = inFile.read() 00209 inFile.close() 00210 00211 materials = parseInFile(inFileContent, predefinedMaterials, config) 00212 twikiString = getTwiki(materials, config) 00213 00214 outFile = open(options.output,"w") 00215 outFile.write(twikiString) 00216 outFile.close() 00217 00218 main()
def twikiExport::parseComment | ( | comment | ) |
Definition at line 116 of file twikiExport.py.
def twikiExport::parseInFile | ( | inFile, | |
predefinedMaterials, | |||
config | |||
) |
Definition at line 89 of file twikiExport.py.
00090 : 00091 comment = "" 00092 materials = [] 00093 i = 0 00094 for line in inFile.split("\n"): 00095 i=i+1 00096 if i < int(config["parsing"]["intro"]): 00097 continue 00098 if not line == "" and line[0] == "#": 00099 material = Material( line , comment ) 00100 if not material.theName == "END": 00101 materials.append( material ) 00102 comment = "" 00103 00104 #print "Name: "+name+" Description: "+description+" mcVolume: "+str(mcVolume) 00105 elif not line == "" and line[0] == "*": 00106 00107 materials[-1].addConstituent(line, predefinedMaterials) 00108 else: 00109 ignore = False 00110 for char in config["parsing"]["ignorelines"]: 00111 if len(line.strip()) == line.strip().count(char) and not len(line) == 0: 00112 ignore = True 00113 if not ignore: 00114 comment += line+"\n" 00115 return materials
def twikiExport::readConfig | ( | fileName | ) |
Definition at line 170 of file twikiExport.py.
def twikiExport::readMaterialFile | ( | fileName | ) |
Definition at line 152 of file twikiExport.py.
def twikiExport::readSection | ( | config, | |
section | |||
) |
Definition at line 163 of file twikiExport.py.