Changeset 546
- Timestamp:
- 12/09/07 14:12:05 (17 years ago)
- Location:
- pkpgcounter/trunk/pkpgpdls
- Files:
-
- 1 modified
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/analyzer.py
r545 r546 30 30 import version, pdlparser, postscript, pdf, pcl345, pclxl, hbp, \ 31 31 pil, mscrap, cfax, lidil, escp2, dvi, tiff, ooo, zjstream, \ 32 bj, qpdl, spl1, escpages03, plain32 netpbm, bj, qpdl, spl1, escpages03, plain 33 33 import inkcoverage 34 34 … … 165 165 escpages03, \ 166 166 bj, \ 167 netpbm, \ 167 168 pil, \ 168 169 mscrap, \ -
pkpgcounter/trunk/pkpgpdls/netpbm.py
r527 r546 21 21 # 22 22 23 """This modules implements a page counter for plain textdocuments."""23 """This modules implements a page counter for PNM (ascii) documents.""" 24 24 25 25 import pdlparser … … 27 27 28 28 class 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.""" 33 30 required = [ "a2ps | enscript", "gs" ] 34 31 openmode = "rU" … … 40 37 If it's impossible to find one we consider it's not plain text. 41 38 """ 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] 49 42 return True 50 43 else : … … 52 45 53 46 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.""" 57 48 pagecount = 0 58 linecount = 049 marker = self.marker 59 50 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