Package PyFoam :: Package Basics :: Module LineReader
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Basics.LineReader

 1  #  ICE Revision: $Id$  
 2  """Read a file line by line""" 
 3   
 4  from PyFoam.Infrastructure.Logging import foamLogger 
 5   
6 -class LineReader(object):
7 """Read a line from a file 8 9 The line is stripped of whitespaces at the start and the end of 10 the line and stored in a variable self.line""" 11
12 - def __init__(self):
13 self.line="" 14 self.goOn=True 15 self.wasInterupted=False 16 self.bytes=0L
17
18 - def bytesRead(self):
19 """@return: number of bytes that were already read""" 20 return self.bytes
21
22 - def userSaidStop(self):
23 """@return: whether the reader caught a Keyboard-interrupt""" 24 return self.wasInterupted
25
26 - def read(self,fh):
27 """reads the next line 28 29 fh - filehandle to read from 30 31 Return value: False if the end of the file was reached. True 32 otherwise""" 33 34 if not self.goOn: 35 return False 36 37 try: 38 self.line=fh.readline() 39 self.bytes+=len(self.line) 40 except KeyboardInterrupt,e: 41 foamLogger().warning("Keyboard Interrupt") 42 print " Interrupted by the Keyboard" 43 self.wasInterupted=True 44 self.goOn=False 45 self.line="" 46 return False 47 48 if len(self.line)>0: 49 status=True 50 else: 51 status=False 52 self.line=self.line.strip() 53 54 return status
55