Show
Ignore:
Timestamp:
04/04/05 00:28:37 (19 years ago)
Author:
jerome
Message:

Moved the code into the submodules

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pdlanalyzer/escp2.py

    r191 r193  
     1#! /usr/bin/env python 
     2# -*- coding: ISO-8859-15 -*- 
    13# 
    24# pkpgcounter : a generic Page Description Language parser 
     
    1921# $Id$ 
    2022# 
     23 
     24import sys 
     25 
     26from pdlanalyzer.pdlparser import PDLParser 
     27 
     28class ESCP2Parser(PDLParser) : 
     29    """A parser for ESC/P2 documents.""" 
     30    def getJobSize(self) :     
     31        """Counts pages in an ESC/P2 document.""" 
     32        # with Gimpprint, at least, for each page there 
     33        # are two Reset Printer sequences (ESC + @) 
     34        marker1 = "\033@" 
     35         
     36        # with other software or printer driver, we 
     37        # may prefer to search for "\r\n\fESCAPE" 
     38        # or "\r\fESCAPE" 
     39        marker2r = "\r\f\033" 
     40        marker2rn = "\r\n\f\033" 
     41         
     42        # and ghostscript's stcolor for example seems to 
     43        # output ESC + @ + \f for each page plus one 
     44        marker3 = "\033@\f" 
     45         
     46        # while ghostscript's escp driver outputs instead 
     47        # \f + ESC + @ 
     48        marker4 = "\f\033@" 
     49         
     50        data = self.infile.read() 
     51        pagecount1 = data.count(marker1) 
     52        pagecount2 = max(data.count(marker2r), data.count(marker2rn)) 
     53        pagecount3 = data.count(marker3) 
     54        pagecount4 = data.count(marker4) 
     55             
     56        if pagecount2 :     
     57            return pagecount2 
     58        elif pagecount3 > 1 :      
     59            return pagecount3 - 1 
     60        elif pagecount4 :     
     61            return pagecount4 
     62        else :     
     63            return int(pagecount1 / 2)        
     64         
     65def test() :         
     66    """Test function.""" 
     67    raise RuntimeError, "Not implemented !" 
     68     
     69if __name__ == "__main__" :     
     70    test()