Changeset 1449

Show
Ignore:
Timestamp:
05/04/04 14:21:55 (20 years ago)
Author:
jalet
Message:

Now uses mmap in PCL mode

Location:
pykota/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pkpgcounter

    r1448 r1449  
    2424# 
    2525# $Log$ 
     26# Revision 1.4  2004/05/04 12:21:55  jalet 
     27# Now uses mmap in PCL mode 
     28# 
    2629# Revision 1.3  2004/05/04 04:39:26  jalet 
    2730# Better PCL support 
     
    3639 
    3740import sys 
     41import os 
     42import mmap 
    3843import tempfile 
    3944 
     
    8186    # published under the terms of the GNU General Public Licence v2. 
    8287    #  
    83     # Backported from C to Python by Jerome Alet 
     88    # Backported from C to Python by Jerome Alet, then enhanced 
     89    # with more PCL tags detected. I think all the necessary PCL tags 
     90    # are recognized to correctly handle PCL5e files wrt their number 
     91    # of pages 
    8492    #  
     93    infileno = infile.fileno() 
     94    infile = mmap.mmap(infileno, os.fstat(infileno).st_size, access=mmap.ACCESS_READ) 
    8595    tagsends = { "&n" : "W", "&b": "W", "*i" : "W", "*l" : "W", "*m" : "W", "*v": "W", "*c" : "W", "(f" : "W", "*b" : "VW", "(s" : "W", ")s" : "W", "&p" : "X", "&l" : "X" }  
    8696    copies = 1 
    8797    pagecount = 0 
    8898    tag = None 
     99    position = 0 
    89100    while 1 : 
    90         char = infile.read(1)   # TODO : speed this up if possible 
     101        try : 
     102            char = infile[position] 
     103        except IndexError :     # EOF     
     104            break 
     105        position += 1 
    91106        if not char : 
    92107            break 
     
    110125            #     <ESC>&p###X -> Start of a non printable characters block 
    111126            # 
    112             tagstart = infile.read(1) 
     127            tagstart = infile[position] 
     128            position += 1 
    113129            if tagstart in "E9=YZ" : # one byte PCL tag 
    114130                continue             # skip to next tag 
    115             tag = tagstart + infile.read(1) 
     131            tag = tagstart + infile[position] 
     132            position += 1 
    116133            try : 
    117134                tagend = tagsends[tag] 
     
    122139                size = 0 
    123140                while 1 : 
    124                     char = infile.read(1) 
     141                    char = infile[position] 
     142                    position += 1 
    125143                    if not char.isdigit() : 
    126144                        break 
     
    137155                            # which is before the string itself 
    138156                            size += 1 
    139                         infile.read(size)  
     157                        position += size     
    140158    return copies * pagecount         
    141159 
  • pykota/trunk/NEWS

    r1448 r1449  
    2828           
    2929        - improved PCL support in pkpgcounter.   
     30         
     31        - pkpgcounter now uses mmap to speed things up : duration 
     32          is halved with the sample 87 pages PCL document I use. 
    3033           
    3134    - 1.19alpha3 :