Show
Ignore:
Timestamp:
09/15/06 11:19:37 (18 years ago)
Author:
jerome
Message:

Added plain text parser with support for both page counting and ink coverage.

Location:
pkpgcounter/trunk/pkpgpdls
Files:
2 modified

Legend:

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

    r414 r418  
    2626import sys 
    2727import os 
    28 import mmap 
    2928 
    3029import pdlparser 
     
    3433class Parser(pdlparser.PDLParser) : 
    3534    """A parser for plain text documents.""" 
     35    enscript = 'enscript --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     36    a2ps = 'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     37    def __init__(self, infile, debug=0, firstblock=None, lastblock=None) : 
     38        """Initialize the plain text parser.""" 
     39        pdlparser.PDLParser.__init__(self, infile, debug, firstblock, lastblock) 
     40         
     41        # Tries to detect is a plain text to PostScript command line tool is available 
     42        # and use the first one we find. 
     43        paths = os.environ.get("PATH", "/usr/local/bin:/usr/bin:/bin").split(os.pathsep) 
     44        for cmd in ("enscript", "a2ps") : 
     45            for path in paths : 
     46                if os.path.exists(os.path.join(path, cmd)) : 
     47                    self.totiffcommand = getattr(self, cmd) 
     48                    return 
     49         
    3650    def isValid(self) :     
    3751        """Returns True if data is plain text, else False. 
  • pkpgcounter/trunk/pkpgpdls/version.py

    r408 r418  
    2323 
    2424 
    25 __version__ = "2.01alpha" 
     25__version__ = "2.10" 
    2626 
    2727__doc__ = """pkpgcounter : a generic Page Description Languages parser."""