本文整理汇总了Python中PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile.update方法的典型用法代码示例。如果您正苦于以下问题:Python ParsedParameterFile.update方法的具体用法?Python ParsedParameterFile.update怎么用?Python ParsedParameterFile.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile
的用法示例。
在下文中一共展示了ParsedParameterFile.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import update [as 别名]
def run(self):
if self.opts.template=="stdin" and self.opts.pickledFileRead=="stdin":
self.error("Can't simultanously read pickled data and the tempalte from the standard input")
content=None
if self.opts.template=="stdin":
content=sys.stdin.read()
data=None
if self.opts.pickledFileRead:
data=self.readPickledData()
fName=None
if len(self.parser.getArgs())==2:
if self.opts.pickledFileRead:
self.error("old-format mode does not work with pickled input")
if self.opts.outputFile:
self.error("--output-file is not valid for the old format")
# old school implementation
fName=self.parser.getArgs()[0]
vals=eval(self.parser.getArgs()[1])
if type(vals)==str:
# fix a problem with certain shells
vals=eval(vals)
if self.opts.template==None:
template=fName+".template"
else:
template=self.opts.template
if content:
t=TemplateFileOldFormat(content=content)
else:
t=TemplateFileOldFormat(name=template)
elif len(self.parser.getArgs())==0:
if self.opts.template==None and self.opts.outputFile!=None and self.opts.outputFile!="stdin":
self.opts.template=self.opts.outputFile+".template"
self.warning("Automatically setting template to",self.opts.template)
vals={}
if self.opts.useDefaults and self.opts.template!=None and self.opts.template!="stdin":
name,ext=path.splitext(self.opts.template)
defaultName=name+".defaults"
if path.exists(defaultName):
self.warning("Reading default values from",defaultName)
vals=ParsedParameterFile(defaultName,
noHeader=True,
doMacroExpansion=True).getValueDict()
vals.update(self.parameters)
if self.opts.values:
vals.update(eval(self.opts.values))
elif self.opts.valuesDict:
vals.update(ParsedParameterFile(self.opts.valuesDict,
noHeader=True,
doMacroExpansion=True).getValueDict())
elif data:
vals.update(data["values"])
elif len(self.parameters)==0:
self.error("Either specify the values with --values-string or --values-dictionary or in the pickled input data")
if self.opts.dumpUsed:
maxLen=max([len(k) for k in vals.keys()])
formatString=" %%%ds | %%s" % maxLen
print_("Used values")
print_(formatString % ("Name","Value"))
print_("-"*(maxLen+30))
for k,v in iteritems(vals):
print_(formatString % (k,v))
if content:
t=TemplateFile(content=content,
tolerantRender=self.opts.tolerantRender,
allowExec=self.opts.allowExec,
expressionDelimiter=self.opts.expressionDelimiter,
assignmentLineStart=self.opts.assignmentLineStart)
elif data:
t=TemplateFile(content=data["template"],
tolerantRender=self.opts.tolerantRender,
allowExec=self.opts.allowExec,
expressionDelimiter=self.opts.expressionDelimiter,
assignmentLineStart=self.opts.assignmentLineStart)
elif self.opts.template:
t=TemplateFile(name=self.opts.template,
tolerantRender=self.opts.tolerantRender,
allowExec=self.opts.allowExec,
expressionDelimiter=self.opts.expressionDelimiter,
assignmentLineStart=self.opts.assignmentLineStart)
else:
self.error("Template unspecified")
if self.opts.outputFile:
fName=self.opts.outputFile
else:
self.error("Either specify 2 arguments (file and values) for old format or no arguments for the new format")
if self.opts.stdout:
print_(t.getString(vals))
elif fName:
try:
t.writeToFile(fName,vals)
#.........这里部分代码省略.........