本文整理汇总了Python中PyFoam.Basics.LineReader.LineReader类的典型用法代码示例。如果您正苦于以下问题:Python LineReader类的具体用法?Python LineReader怎么用?Python LineReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LineReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purgeFile
def purgeFile(self):
"""Undo all the manipulations done by PyFOAM
Goes through the file and removes all lines that were added"""
rmExp= re.compile("^"+self.removedString+"(.*)$")
addExp=re.compile("^(.*)"+self.addedString+"$")
l=LineReader()
self.openFile()
(fh,fn)=self.makeTemp()
while l.read(self.fh):
toPrint=l.line
m=addExp.match(l.line)
if m!=None:
continue
m=rmExp.match(l.line)
if m!=None:
toPrint=m.group(1)
self.writeEncoded(fh,toPrint+"\n")
self.closeFile()
fh.close()
os.rename(fn,self.name)
示例2: replaceParameter
def replaceParameter(self,parameter,newval):
"""writes the value of a parameter
:param parameter: name of the parameter
:param newval: the new value
:return: old value of the parameter"""
oldVal=self.readParameter(parameter)
exp=self.parameterPattern(parameter)
l=LineReader()
self.openFile()
(fh,fn)=self.makeTemp()
while l.read(self.fh):
toPrint=l.line
m=exp.match(l.line)
if m!=None:
if m.group(1).find(self.removedString)<0:
toPrint =self.removedString+l.line+"\n"
toPrint+=parameter+" "+str(newval)+"; "+self.addedString
fh.write(toPrint+"\n")
self.closeFile()
fh.close()
os.rename(fn,self.name)
return oldVal
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:31,代码来源:ParameterFile.py
示例3: refineMesh
def refineMesh(self,factors,offset=(0,0,0)):
"""Refine the Mesh by multiplying the number of cells in the blocks
@param factors: either a scalar to scale in all directions or a
tuple with the value for each direction
@param offset: an optional tuple for an additionnal offset value
for each direction"""
if type(factors)!=tuple:
f=(factors,factors,factors)
else:
f=factors
startPattern=re.compile("^\s*blocks")
endPattern=re.compile("^\s\);")
hexPattern=re.compile("^(\s*hex\s*\(.+\)\s+\(\s*)(\d+)\s+(\d+)\s+(\d+)(\s*\).*)$")
inBlock=False
l=LineReader()
self.openFile()
(fh,fn)=self.makeTemp()
while l.read(self.fh):
toPrint=l.line
if not inBlock:
if startPattern.match(l.line):
inBlock=True
else:
if endPattern.match(l.line):
inBlock=False
else:
m=hexPattern.match(l.line)
if m!=None:
g=m.groups()
toPrint =self.removedString+l.line+"\n"
toPrint+="%s%d %d %d%s" % (
g[0],
int(g[1])*f[0]+offset[0],
int(g[2])*f[1]+offset[1],
int(g[3])*f[2]+offset[2],
g[4])
toPrint+=" "+self.addedString
fh.write(toPrint+"\n")
self.closeFile()
fh.close()
os.rename(fn,self.name)
示例4: readInternalUniform
def readInternalUniform(self):
"""read the value of the internal field"""
exp=self.internalPatternUniform()
erg=""
l=LineReader()
self.openFile()
while l.read(self.fh):
m=exp.match(l.line)
if m!=None:
erg=m.group(1)
break
self.closeFile()
return erg
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:16,代码来源:SolutionFile.py
示例5: readDimension
def readDimension(self):
"""read the dimension of the field"""
exp=self.dimensionPattern()
erg=""
l=LineReader()
self.openFile()
while l.read(self.fh):
m=exp.match(l.line)
if m!=None:
erg=m.group(1)
break
self.closeFile()
return erg
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:16,代码来源:SolutionFile.py
示例6: getSize
def getSize(self):
""":return: the size of the list"""
size=-1 # should be long
l=LineReader()
self.openFile()
while l.read(self.fh):
try:
size=long(l.line)
break
except ValueError:
pass
self.closeFile()
return size
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:18,代码来源:ListFile.py
示例7: readParameter
def readParameter(self,parameter):
"""reads the value of a parameter
parameter - name of the parameter"""
exp=self.parameterPattern(parameter)
l=LineReader()
self.openFile()
erg=""
while l.read(self.fh):
m=exp.match(l.line)
if m!=None:
if m.group(1).find(self.removedString)<0:
erg=m.group(2)
break
self.closeFile()
return erg
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:20,代码来源:ParameterFile.py
示例8: __init__
def __init__(self,filenames,
silent=False,
tailLength=1000,
sleep=0.1,
follow=True):
""":param filename: name of the logfile to watch
:param silent: if True no output is sent to stdout
:param tailLength: number of bytes at the end of the fail that should be output.
:param follow: if the end of the file is reached wait for further input
Because data is output on a per-line-basis
:param sleep: interval to sleep if no line is returned"""
if type(filenames) is list:
meshTimes=[]
createMesh="Create mesh for time = "
for fName in filenames:
meshTime=None
with open(fName) as f:
for l in f.readlines()[:100]:
if l.find(createMesh)==0:
meshTime=float(l[len(createMesh):])
break
meshTimes.append((fName,meshTime))
meshTimes.sort(key=lambda x:1e50 if x[1] is None else x[1])
filenames=[m[0] for m in meshTimes]
self.filename=filenames[0]
self.nextFiles=filenames[1:]
self.changeTimes=[m[1] for m in meshTimes[1:]]
else:
self.filename=filenames
self.nextFiles=[]
self.changeTimes=[]
self._changeFileHooks=[]
self.silent=silent
self.tail=tailLength
self.sleep=sleep
self.follow=follow
self.isTailing=False
if not path.exists(self.filename):
print_("Error: Logfile ",self.filename,"does not exist")
self.reader=LineReader(config().getboolean("SolverOutput","stripSpaces"))
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:45,代码来源:BasicWatcher.py
示例9: __init__
def __init__(self,progress=False):
"""
@param progress: Print time progress on console?
"""
self.analyzers={}
self.time=""
self.oDir=""
self.line=LineReader()
self.timeListeners=[]
self.timeTriggers=[]
self.progressOut=None
if progress:
self.progressOut=ProgressOutput(stdout)
tm=TimeLineAnalyzer(progress=progress)
self.addAnalyzer("Time",tm)
tm.addListener(self.setTime)
示例10: __init__
def __init__(self,cmdline,runner):
""":param cmdline:cmdline - Command line of the OpenFOAM command
:param runner: the Runner-object that started this thread"""
Thread.__init__(self)
self.cmdline=cmdline
self.runner=runner
self.output=None
self.reader=LineReader(config().getboolean("SolverOutput","stripSpaces"))
self.keyboardInterupted=False
self.isLinux=False
self.isDarwin=False
self.isWindows=False
self.threadPid=-1
self.who=RUSAGE_CHILDREN
if uname()[0]=="Linux":
self.isLinux=True
self.linuxMaxMem=0
elif uname()[0]=="Darwin":
self.isDarwin=True
elif uname()[0]=="Windows":
self.isWindows=True
self.resStart=None
self.resEnd=None
self.timeStart=None
self.timeEnd=None
self.timerTime=5.
self.stateLock=Lock()
self.setState(False)
self.status=None
self.returncode=None
self.lineLock=Lock()
self.line=""
self.stateLock.acquire()
开发者ID:Unofficial-Extend-Project-Mirror,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:42,代码来源:FoamThread.py
示例11: __init__
def __init__(self,progress=False):
"""
@param progress: Print time progress on console?
"""
self.analyzers={}
self.time=""
self.oDir=""
self.line=LineReader(config().getboolean("SolverOutput","stripSpaces"))
self.timeListeners=[]
self.timeTriggers=[]
self.customExpr=re.compile("Custom([0-9]+)_(.+)")
self.progressOut=None
if progress:
self.progressOut=ProgressOutput(stdout)
tm=TimeLineAnalyzer(progress=progress)
self.addAnalyzer("Time",tm)
tm.addListener(self.setTime)
示例12: __init__
def __init__(self,cmdline,runner):
"""@param cmdline:cmdline - Command line of the OpenFOAM command
@param runner: the Runner-object that started this thread"""
Thread.__init__(self)
self.cmdline=cmdline
self.runner=runner
self.output=None
self.reader=LineReader()
self.isLinux=False
self.isDarwin=False
self.threadPid=-1
self.who=RUSAGE_CHILDREN
if uname()[0]=="Linux":
self.isLinux=True
self.linuxMaxMem=0
elif uname()[0]=="Darwin":
self.isDarwin=True
self.resStart=None
self.resEnd=None
self.timeStart=None
self.timeEnd=None
self.timerTime=5.
self.stateLock=Lock()
self.setState(False)
self.status=None
self.returncode=None
self.lineLock=Lock()
self.line=""
self.stateLock.acquire()
示例13: __init__
def __init__(self,filename,
silent=False,
tailLength=1000,
sleep=0.1,
follow=True):
"""@param filename: name of the logfile to watch
@param silent: if True no output is sent to stdout
@param tailLength: number of bytes at the end of the fail that should be output.
@param follow: if the end of the file is reached wait for further input
Because data is output on a per-line-basis
@param sleep: interval to sleep if no line is returned"""
self.filename=filename
self.silent=silent
self.tail=tailLength
self.sleep=sleep
self.follow=follow
self.isTailing=False
if not path.exists(self.filename):
print_("Error: Logfile ",self.filename,"does not exist")
self.reader=LineReader()
示例14: FoamThread
class FoamThread(Thread):
"""Thread running an OpenFOAM command
The output of the command can be accessed in a thread-safe manner,
line by line
Designed to be used by the BasicRunner-class"""
def __init__(self,cmdline,runner):
"""@param cmdline:cmdline - Command line of the OpenFOAM command
@param runner: the Runner-object that started this thread"""
Thread.__init__(self)
self.cmdline=cmdline
self.runner=runner
self.output=None
self.reader=LineReader()
self.isLinux=False
self.isDarwin=False
self.threadPid=-1
self.who=RUSAGE_CHILDREN
if uname()[0]=="Linux":
self.isLinux=True
self.linuxMaxMem=0
elif uname()[0]=="Darwin":
self.isDarwin=True
self.resStart=None
self.resEnd=None
self.timeStart=None
self.timeEnd=None
self.timerTime=5.
self.stateLock=Lock()
self.setState(False)
self.status=None
self.returncode=None
self.lineLock=Lock()
self.line=""
self.stateLock.acquire()
def run(self):
"""start the command"""
# print "Starting ",self.cmdline
self.resStart=getrusage(self.who)
self.timeStart=time()
if sys.version_info<(2,4):
run=Popen4(self.cmdline)
self.output=run.fromchild
else:
run=subprocess.Popen(self.cmdline,shell=True,bufsize=0,
stdin=subprocess.PIPE,stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,close_fds=True)
self.output=run.stdout
self.run=run
self.threadPid=run.pid
foamLogger().info("Started with PID %d" % self.threadPid)
if self.isLinux:
# print "Starting Timer"
self.timer=Timer(0.1*self.timerTime,getLinuxMem,args=[self])
self.timer.start()
# print "Starting Timer"
self.timer2=Timer(0.5*self.timerTime,checkForStopFile,args=[self])
self.timer2.start()
self.hasSomethingToSay=True
self.stateLock.release()
try:
# print "Waiting",time()
self.status=run.wait()
# Python 2.3 on Mac OS X never seems to reach this point
# print "After wait",time()
# print "Status:",self.status
# to give a chance to read the remaining output
if self.hasSomethingToSay:
sleep(2.)
while self.reader.read(self.output):
print "Unused output:",self.reader.line
except OSError,e:
print "Exeption caught:",e
self.stopTimer()
self.threadPid=-1
self.resEnd=getrusage(self.who)
self.timeEnd=time()
# print "End:",self.timeEnd
# print "Returned",self.status
#.........这里部分代码省略.........
示例15: FoamLogAnalyzer
class FoamLogAnalyzer(object):
"""Base class for all analyzers
Administrates and calls a number of LogLineAnlayzers for each
line"""
def __init__(self,progress=False):
"""
@param progress: Print time progress on console?
"""
self.analyzers={}
self.time=""
self.oDir=""
self.line=LineReader()
self.timeListeners=[]
self.timeTriggers=[]
self.customExpr=re.compile("Custom([0-9]+)_(.+)")
self.progressOut=None
if progress:
self.progressOut=ProgressOutput(stdout)
tm=TimeLineAnalyzer(progress=progress)
self.addAnalyzer("Time",tm)
tm.addListener(self.setTime)
def tearDown(self):
"""Remove reference to self in children (hoping to remove
circular dependencies)"""
for a in list(self.analyzers.values()):
a.tearDown()
a.setParent(None)
def collectData(self):
"""Collect dictionaries of collected data (current state)
from the analyzers
@return: the dictionary"""
result={}
for nm in self.analyzers:
data=self.analyzers[nm].getCurrentData()
if len(data)>0:
m=self.customExpr.match(nm)
if m:
if not "Custom" in result:
result["Custom"]={}
nr,name=m.groups()
result["Custom"][name]=data
# this will store custom data twice. But we'll keep it
# for backward-compatibility
result[nm]=data
return result
def setTime(self,time):
"""Sets the time and alert all the LineAnalyzers that the time has changed
@param time: the new value of the time
"""
if time!=self.time:
if self.progressOut:
self.progressOut.reset()
self.time=time
for listener in self.timeListeners:
listener.timeChanged()
for nm in self.analyzers:
self.analyzers[nm].timeChanged()
self.checkTriggers()
data=self.collectData()
for listener in self.timeListeners:
try:
# make sure everyone gets a separate copy
listener.setDataSet(deepcopy(data))
except AttributeError:
# seems that the listener doesn't want the data
pass
def writeProgress(self,msg):
"""Write a message to the progress output"""
if self.progressOut:
self.progressOut(msg)
def addTimeListener(self,listener):
"""@param listener: An object that is notified when the time changes. Has to
implement a timeChanged method"""
if not 'timeChanged' in dir(listener):
error("Error. Object has no timeChanged-method:"+str(listener))
else:
self.timeListeners.append(listener)
def listAnalyzers(self):
"""@returns: A list with the names of the Analyzers"""
return list(self.analyzers.keys())
def hasAnalyzer(self,name):
#.........这里部分代码省略.........