Changeset 428 for pkpgcounter/trunk

Show
Ignore:
Timestamp:
10/17/06 09:41:55 (18 years ago)
Author:
jerome
Message:

Improved ink accounting by allowing several commands to be launch to convert to TIFF in case one of them fails.

Location:
pkpgcounter/trunk/pkpgpdls
Files:
9 modified

Legend:

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

    r415 r428  
    3333class Parser(pdlparser.PDLParser) : 
    3434    """A parser for DVI documents.""" 
    35     totiffcommand = 'cat >%(fname)s && dvips -q -o - %(fname)s | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     35    totiffcommands = [ 'cat >%(fname)s && dvips -q -o - %(fname)s | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ] 
    3636    def isValid(self) :         
    3737        """Returns True if data is DVI, else False.""" 
  • pkpgcounter/trunk/pkpgpdls/oldpcl345.py

    r426 r428  
    3434class Parser(pdlparser.PDLParser) : 
    3535    """A parser for PCL3, PCL4, PCL5 documents.""" 
    36     totiffcommand = 'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     36    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',  
     37                       'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
     38                     ] 
    3739    mediasizes = {  # ESC&l####A 
    3840                    0 : "Default", 
  • pkpgcounter/trunk/pkpgpdls/pcl345.py

    r426 r428  
    3939class Parser(pdlparser.PDLParser) : 
    4040    """A parser for PCL3, PCL4, PCL5 documents.""" 
    41     totiffcommand = 'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     41    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',  
     42                       'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
     43                     ] 
    4244    mediasizes = {  # ESC&l####A 
    4345                    0 : "Default", 
  • pkpgcounter/trunk/pkpgpdls/pclxl.py

    r426 r428  
    3434class Parser(pdlparser.PDLParser) : 
    3535    """A parser for PCLXL (aka PCL6) documents.""" 
    36     totiffcommand = 'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     36    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -',  
     37                       'pcl6 -sDEVICE=pswrite -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
     38                     ] 
    3739    mediasizes = {  
    3840                    0 : "Letter", 
  • pkpgcounter/trunk/pkpgpdls/pdf.py

    r415 r428  
    4343class Parser(pdlparser.PDLParser) : 
    4444    """A parser for PDF documents.""" 
    45     totiffcommand = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     45    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ] 
    4646    def isValid(self) :     
    4747        """Returns True if data is PDF, else False.""" 
  • pkpgcounter/trunk/pkpgpdls/pdlparser.py

    r425 r428  
    2323 
    2424import sys 
     25import os 
    2526import popen2 
    2627 
     
    4142class PDLParser : 
    4243    """Generic PDL parser.""" 
    43     totiffcommand = None        # Default command to convert to TIFF 
     44    totiffcommands = None        # Default command to convert to TIFF 
    4445    def __init__(self, infile, debug=0, firstblock=None, lastblock=None) : 
    4546        """Initialize the generic parser.""" 
     
    8990           Writes TIFF datas to the file named by fname. 
    9091        """    
    91         if self.totiffcommand : 
    92             commandline = self.totiffcommand % locals() 
    93             child = popen2.Popen4(commandline) 
    94             try : 
     92        if self.totiffcommands : 
     93            for totiffcommand in self.totiffcommands : 
     94                self.infile.seek(0) 
     95                error = False 
     96                commandline = totiffcommand % locals() 
     97                child = popen2.Popen4(commandline) 
    9598                try : 
    96                     data = self.infile.read(MEGABYTE)     
    97                     while data : 
    98                         child.tochild.write(data) 
    99                         data = self.infile.read(MEGABYTE) 
    100                 except (IOError, OSError), msg :     
    101                     raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 
    102             finally :     
    103                 child.tochild.close()     
    104                 child.fromchild.close() 
    105                  
    106             try : 
    107                 child.wait() 
    108             except OSError, msg :     
    109                 raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 
     99                    try : 
     100                        data = self.infile.read(MEGABYTE)     
     101                        while data : 
     102                            child.tochild.write(data) 
     103                            data = self.infile.read(MEGABYTE) 
     104                    except (IOError, OSError) :     
     105                        error = True 
     106                finally :     
     107                    child.tochild.close()     
     108                    child.fromchild.close() 
     109                     
     110                try : 
     111                    child.wait() 
     112                except OSError :     
     113                    error = True 
     114                     
     115                if not os.path.exists(fname) : 
     116                    error = True 
     117                elif not os.stat(fname).st_size : 
     118                    error = True 
     119                else :         
     120                    break       # Conversion worked fine it seems. 
     121                self.logdebug("Command failed : %s" % repr(commandline)) 
     122            if error : 
     123                raise PDLParserError, "Problem during conversion to TIFF." 
    110124        else :         
    111125            raise PDLParserError, "Impossible to compute ink coverage for this file format." 
  • pkpgcounter/trunk/pkpgpdls/plain.py

    r422 r428  
    3333class Parser(pdlparser.PDLParser) : 
    3434    """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          
     35    totiffcommands = [ 'enscript --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
     36                       'a2ps --borders 0 --quiet --portrait --no-header --columns 1 --output - | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -', 
     37                     ]   
    5038    def isValid(self) :     
    5139        """Returns True if data is plain text, else False. 
  • pkpgcounter/trunk/pkpgpdls/postscript.py

    r415 r428  
    3434class Parser(pdlparser.PDLParser) : 
    3535    """A parser for PostScript documents.""" 
    36     totiffcommand = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
     36    totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ] 
    3737    def isValid(self) :     
    3838        """Returns True if data is PostScript, else False.""" 
  • pkpgcounter/trunk/pkpgpdls/tiff.py

    r415 r428  
    3333class Parser(pdlparser.PDLParser) : 
    3434    """A parser for TIFF documents.""" 
    35     totiffcommand = "cat >%(fname)s" 
     35    totiffcommands = [ "cat >%(fname)s" ] 
    3636    def isValid(self) :         
    3737        """Returns True if data is TIFF, else False."""