Changeset 488 for pkpgcounter/trunk
- Timestamp:
- 11/17/07 16:10:02 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/lidil.py
r485 r488 32 32 import os 33 33 import mmap 34 from struct import unpack 34 import struct 35 35 36 36 import pdlparser … … 72 72 def getJobSize(self) : 73 73 """Computes the number of pages in a HP LIDIL document.""" 74 pagecount = 0 74 unpack = struct.unpack 75 ejectpage = loadpage = 0 75 76 infileno = self.infile.fileno() 76 77 minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) … … 91 92 except struct.error : 92 93 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 94 if packettype == PACKET_TYPE_COMMAND : 95 if commandnumber == LDL_LOAD_PAGE : 96 loadpage += 1 97 elif commandnumber == LDL_EJECT_PAGE : 98 ejectpage += 1 96 99 pos += (cmdlength + datalength) 97 100 except IndexError : # EOF ? … … 99 102 finally : 100 103 minfile.close() 101 return pagecount 104 105 # Number of page eject commands should be sufficient, 106 # but we never know : someone could try to cheat the printer 107 # by loading a page but not ejecting it, and ejecting it manually 108 # later on. Not sure if the printers would support this, but 109 # taking the max value works around the problem in any case. 110 self.logdebug("Load : %i Eject : %i" % (loadpage, ejectpage)) 111 return max(loadpage, ejectpage) 102 112 103 113 if __name__ == "__main__" :