Changeset 3042

Show
Ignore:
Timestamp:
10/16/06 18:28:19 (18 years ago)
Author:
jerome
Message:

Simplified code : pkpgcounter's code already opens the data file.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/ink.py

    r3036 r3042  
    6969            else :      
    7070                options = analyzer.AnalyzerOptions(colorspace=colorspace, resolution=resolution) 
    71                 infile = open(self.filter.DataFile, "rb") 
    7271                try : 
    73                     try : 
    74                         parser = analyzer.PDLAnalyzer(infile, options) 
    75                         (cspace, pages) = parser.getInkCoverage() 
    76                         cspacelabels = self.cspaceExpanded[cspace] 
    77                         for page in pages : 
    78                             colordict = {} 
    79                             for color in page.keys() : 
    80                                 colordict[cspacelabels[color]] = page[color] 
    81                             self.inkUsage.append(colordict)     
    82                         jobsize = len(pages) 
    83                         self.filter.logdebug("Ink usage : %s ===> %s" % (cspace, repr(self.inkUsage))) 
    84                     except pdlparser.PDLParserError, msg :     
    85                         # Here we just log the failure, but 
    86                         # we finally ignore it and return 0 since this 
    87                         # computation is just an indication of what the 
    88                         # job's size MAY be. 
    89                         self.filter.printInfo(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn") 
    90                     else :     
    91                         if self.filter.InputFile is not None : 
    92                             # when a filename is passed as an argument, the backend  
    93                             # must generate the correct number of copies. 
    94                             jobsize *= self.filter.Copies 
    95                 finally :             
    96                     infile.close()         
     72                    parser = analyzer.PDLAnalyzer(self.filter.DataFile, options) 
     73                    (cspace, pages) = parser.getInkCoverage() 
     74                    cspacelabels = self.cspaceExpanded[cspace] 
     75                    for page in pages : 
     76                        colordict = {} 
     77                        for color in page.keys() : 
     78                            colordict[cspacelabels[color]] = page[color] 
     79                        self.inkUsage.append(colordict)     
     80                    jobsize = len(pages) 
     81                    self.filter.logdebug("Ink usage : %s ===> %s" % (cspace, repr(self.inkUsage))) 
     82                except pdlparser.PDLParserError, msg :     
     83                    # Here we just log the failure, but 
     84                    # we finally ignore it and return 0 since this 
     85                    # computation is just an indication of what the 
     86                    # job's size MAY be. 
     87                    self.filter.printInfo(_("Unable to precompute the job's size with the generic PDL analyzer : %s") % msg, "warn") 
     88                else :     
     89                    if self.filter.InputFile is not None : 
     90                        # when a filename is passed as an argument, the backend  
     91                        # must generate the correct number of copies. 
     92                        jobsize *= self.filter.Copies 
    9793        return jobsize