Show
Ignore:
Timestamp:
11/21/07 16:41:06 (17 years ago)
Author:
jerome
Message:

Re-optimize disk access by not reopening and re-reading first and last block
more than once.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/pdlparser.py

    r492 r493  
    4343    totiffcommands = None        # Default command to convert to TIFF 
    4444    openmode = "rb"              # Default file opening mode 
    45     def __init__(self, filename, debug=0) : 
     45    def __init__(self, filename, firstblock, lastblock, debug=0) : 
    4646        """Initialize the generic parser.""" 
    4747        self.filename = filename 
    4848        self.debug = debug 
    4949        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) 
    5251        if not self.isValid() : 
    5352            raise PDLParserError, "Invalid file format !" 
     
    6160            # parsing will greatly benefit from this. 
    6261            psyco.bind(self.getJobSize) 
     62        self.infile = open(self.filename, self.openmode) 
     63        # self.logdebug("Opened %s in '%s' mode." % (self.filename, self.openmode)) 
    6364             
    6465    def __del__(self) : 
     
    6667        if self.infile : 
    6768            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)     
    8269             
    8370    def logdebug(self, message) :