Changeset 546

Show
Ignore:
Timestamp:
12/09/07 14:12:05 (16 years ago)
Author:
jerome
Message:

Added support for ASCII PNM files.

Location:
pkpgcounter/trunk/pkpgpdls
Files:
1 modified
1 copied

Legend:

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

    r545 r546  
    3030import version, pdlparser, postscript, pdf, pcl345, pclxl, hbp, \ 
    3131       pil, mscrap, cfax, lidil, escp2, dvi, tiff, ooo, zjstream, \ 
    32        bj, qpdl, spl1, escpages03, plain 
     32       netpbm, bj, qpdl, spl1, escpages03, plain 
    3333import inkcoverage 
    3434 
     
    165165                       escpages03, \ 
    166166                       bj, \ 
     167                       netpbm, \ 
    167168                       pil, \ 
    168169                       mscrap, \ 
  • pkpgcounter/trunk/pkpgpdls/netpbm.py

    r527 r546  
    2121# 
    2222 
    23 """This modules implements a page counter for plain text documents.""" 
     23"""This modules implements a page counter for PNM (ascii) documents.""" 
    2424 
    2525import pdlparser 
     
    2727 
    2828class Parser(pdlparser.PDLParser) : 
    29     """A parser for plain text documents.""" 
    30     totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    31                        'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r"%(dpi)i" -sOutputFile="%(outfname)s" -', 
    32                      ]   
     29    """A parser for Netpbm documents.""" 
    3330    required = [ "a2ps | enscript", "gs" ] 
    3431    openmode = "rU"                  
     
    4037           If it's impossible to find one we consider it's not plain text. 
    4138        """    
    42         lines = self.firstblock.split("\r\n") 
    43         if len(lines) == 1 : 
    44             lines = lines[0].split("\r") 
    45             if len(lines) == 1 : 
    46                 lines = lines[0].split("\n") 
    47         if len(lines) > 1 : 
    48             self.logdebug("DEBUG: Input file seems to be in the plain text format.") 
     39        if (self.firstblock[:2] in ("P1", "P2", "P3")) : 
     40            self.logdebug("DEBUG: Input file seems to be in the PNM (ascii) format.") 
     41            self.marker = self.firstblock[:2] 
    4942            return True 
    5043        else :     
     
    5245             
    5346    def getJobSize(self) : 
    54         """Counts pages in a plain text document.""" 
    55         pagesize = 66   # TODO : Does this vary wrt the default page size ? 
    56                         # TODO : /etc/papersize and /etc/paper.config 
     47        """Counts pages in a PNM (ascii) document.""" 
    5748        pagecount = 0 
    58         linecount = 0 
     49        marker = self.marker 
    5950        for line in self.infile : 
    60             if line.endswith("\n") : 
    61                 linecount += 1     
    62                 if (linecount > pagesize) : 
    63                     pagecount += 1 
    64                     linecount = 0 
    65                 else :     
    66                     cnt = line.count("\f") 
    67                     if cnt : 
    68                         pagecount += cnt 
    69                         linecount = 0 
    70             else :         
    71                 raise pdlparser.PDLParserError, "Unsupported file format. Please send the file to %s" % version.__authoremail__ 
    72         return pagecount + 1    # NB : empty files are catched in isValid() 
     51            pagecount += line.split().count(marker) 
     52        return pagecount