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