Show
Ignore:
Timestamp:
11/17/07 14:43:40 (16 years ago)
Author:
jerome
Message:

Almost ok for release.

Files:
1 modified

Legend:

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

    r484 r485  
    3636import pdlparser 
    3737 
     38# Packet types taken from hplip-2.7.10/prnt/ldl.py 
     39PACKET_TYPE_COMMAND = 0 
     40PACKET_TYPE_DISABLE_PACING = 1 
     41PACKET_TYPE_ENABLE_PACING = 2 
     42PACKET_TYPE_RESUME_NORMAL_OPERATION = 3 
     43PACKET_TYPE_DISABLE_RESPONSES = 4 
     44PACKET_TYPE_ENABLE_RESPONSES = 5 
     45PACKET_TYPE_RESET_LIDIL = 6 
     46PACKET_TYPE_SYNC = 7 
     47PACKET_TYPE_SYNC_COMPLETE = 8 
     48 
     49# Command codes we are interested in. 
     50LDL_LOAD_PAGE = 1 
     51LDL_EJECT_PAGE = 2 
     52 
    3853class Parser(pdlparser.PDLParser) : 
    3954    """A parser for HP LIDIL documents.""" 
     
    5772    def getJobSize(self) : 
    5873        """Computes the number of pages in a HP LIDIL document.""" 
    59         ejectpagemarker = "$\x00\x01\x00\x00\x02" # ensure it's a complete packet (ends with '$') 
    60         return 0 
     74        pagecount = 0 
     75        infileno = self.infile.fileno() 
     76        minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
     77        pos = 0 
     78        try : 
     79            try : 
     80                while 1 : 
     81                    if minfile[pos] != "$" :    # Frame Sync 
     82                        raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas" 
     83                    try :     
     84                        (framesync,      
     85                         cmdlength, 
     86                         dummy, 
     87                         packettype, 
     88                         commandnumber, 
     89                         referencenumber, 
     90                         datalength) = unpack(">BHBBBHH", minfile[pos:pos+10]) 
     91                    except struct.error :     
     92                        raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas" 
     93                    if (packettype == PACKET_TYPE_COMMAND) \ 
     94                        and (commandnumber == LDL_EJECT_PAGE) : 
     95                        pagecount += 1 
     96                    pos += (cmdlength + datalength) 
     97            except IndexError : # EOF ? 
     98                pass  
     99        finally :         
     100            minfile.close() 
     101        return pagecount 
    61102 
    62103if __name__ == "__main__" :