Show
Ignore:
Timestamp:
01/13/06 21:33:33 (18 years ago)
Author:
jerome
Message:

Fixed a problem with fast printers : PyKota only saw them
as being 'idle' because they already went from 'idle'
to 'printing' to 'idle' again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/accounters/snmp.py

    r2584 r2615  
    2525ITERATIONDELAY = 1.5   # 1.5 Second 
    2626STABILIZATIONDELAY = 3 # We must read three times the same value to consider it to be stable 
     27NOPRINTINGMAXDELAY = 30 # The printer must begin to print within 30 seconds. 
    2728 
    2829import sys 
     
    9798        def handleAnswer(self, wholeMsg, notusedhere, req): 
    9899            """Decodes and handles the SNMP answer.""" 
    99             self.parent.filter.logdebug("SNMP message : '%s'" % repr(wholeMsg)) 
     100            self.parent.filter.logdebug("SNMP answer : '%s'" % repr(wholeMsg)) 
    100101            ver = alpha.protoVersions[alpha.protoVersionId1] 
    101102            rsp = ver.Message() 
     
    118119                            self.printerStatus = self.values[1] 
    119120                            self.deviceStatus = self.values[2] 
    120                             self.parent.filter.logdebug("SNMP answer is decoded : PageCounter : %s  PrinterStatus : %s  DeviceStatus : %s" % tuple(self.values)) 
     121                            self.parent.filter.logdebug("SNMP answer decoded : PageCounter : %s  PrinterStatus : '%s'  DeviceStatus : '%s'" \ 
     122                                 % (self.printerInternalPageCounter, \ 
     123                                    printerStatusValues.get(self.printerStatus, "ILLEGAL VALUE"), \ 
     124                                    deviceStatusValues.get(self.deviceStatus, "ILLEGAL VALUE"))) 
    121125                        except IndexError :     
    122126                            self.parent.filter.logdebug("SNMP answer is incomplete : %s" % str(self.values)) 
     
    127131        def waitPrinting(self) : 
    128132            """Waits for printer status being 'printing'.""" 
     133            previousValue = self.parent.getLastPageCounter() 
     134            timebefore = time.time() 
    129135            firstvalue = None 
    130136            while 1: 
     
    145151                            # So we can probably quit being sure it is printing. 
    146152                            self.parent.filter.printInfo("Printer %s is lying to us !!!" % self.parent.filter.PrinterName, "warn") 
     153                            break 
     154                        elif (time.time() - timebefore) > NOPRINTINGMAXDELAY : 
     155                            # More than X seconds without the printer being in 'printing' mode 
     156                            # We can safely assume this won't change 
     157                            if self.printerInternalPageCounter == previousValue : 
     158                                # Here the job won't be printed, because probably 
     159                                # the printer rejected it for some reason. 
     160                                self.parent.filter.printInfo("Printer %s probably won't print this job !!!" % self.parent.filter.PrinterName, "warn") 
     161                            else :      
     162                                # Here the job has already been entirely printed, and 
     163                                # the printer has already passed from 'idle' to 'printing' to 'idle' again. 
     164                                self.parent.filter.printInfo("Printer %s has probably already printed this job !!!" % self.parent.filter.PrinterName, "warn") 
    147165                            break 
    148166                self.parent.filter.logdebug(_("Waiting for printer %s to be printing...") % self.parent.filter.PrinterName)     
     
    206224            self.filter = fakeFilter() 
    207225            self.protocolHandler = Handler(self, hostname) 
     226             
     227        def getLastPageCounter(self) :     
     228            return 0 
    208229         
    209230    acc = fakeAccounter()