Changeset 493 for pkpgcounter/trunk/pkpgpdls/pdlparser.py
- Timestamp:
- 11/21/07 16:41:06 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r492 r493 43 43 totiffcommands = None # Default command to convert to TIFF 44 44 openmode = "rb" # Default file opening mode 45 def __init__(self, filename, debug=0) :45 def __init__(self, filename, firstblock, lastblock, debug=0) : 46 46 """Initialize the generic parser.""" 47 47 self.filename = filename 48 48 self.debug = debug 49 49 self.infile = None 50 (self.firstblock, self.lastblock) = self.readBlocks() 51 self.infile = open(self.filename, self.openmode) 50 (self.firstblock, self.lastblock) = (firstblock, lastblock) 52 51 if not self.isValid() : 53 52 raise PDLParserError, "Invalid file format !" … … 61 60 # parsing will greatly benefit from this. 62 61 psyco.bind(self.getJobSize) 62 self.infile = open(self.filename, self.openmode) 63 # self.logdebug("Opened %s in '%s' mode." % (self.filename, self.openmode)) 63 64 64 65 def __del__(self) : … … 66 67 if self.infile : 67 68 self.infile.close() 68 69 def readBlocks(self) :70 """Reads first and last block of the input file."""71 infile = open(self.filename, "rb")72 try :73 firstblock = infile.read(FIRSTBLOCKSIZE)74 try :75 infile.seek(-LASTBLOCKSIZE, 2)76 lastblock = infile.read(LASTBLOCKSIZE)77 except IOError :78 lastblock = ""79 finally :80 infile.close()81 return (firstblock, lastblock)82 69 83 70 def logdebug(self, message) :