Changeset 962

Show
Ignore:
Timestamp:
04/25/03 10:23:23 (21 years ago)
Author:
jalet
Message:

Multiple tries to get the printer's internal page counter, waits for
one minute maximum for the printer to warm up, actually.

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pykota

    r956 r962  
    2323# 
    2424# $Log$ 
     25# Revision 1.26  2003/04/25 08:23:23  jalet 
     26# Multiple tries to get the printer's internal page counter, waits for 
     27# one minute maximum for the printer to warm up, actually. 
     28# 
    2529# Revision 1.25  2003/04/24 11:53:48  jalet 
    2630# Default policy for unknown users/groups is to DENY printing instead 
     
    119123import sys 
    120124import os 
     125import time 
    121126 
    122127from pykota.tool import PyKotaTool, PyKotaToolError 
    123128from pykota.requester import openRequester, PyKotaRequesterError 
     129 
     130MAXTRIES = 6     # maximum number of tries to get the printer's internal page counter 
     131TIMETOSLEEP = 10 # number of seconds to sleep between two tries to get the printer's internal page counter 
    124132 
    125133class PyKotaFilter(PyKotaTool) :     
     
    167175def main() :     
    168176    """Do it, and do it right !""" 
    169          
     177    global MAXTRIES, TIMETOSLEEP 
     178     
    170179    # Initializes the current tool 
    171180    kotafilter = PyKotaFilter()     
     
    179188     
    180189    # Get the page counter directly from the printer itself 
    181     try : 
    182         counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) 
    183     except PyKotaRequesterError, msg : 
    184         # can't get actual page counter, assume printer is off, but warns in log 
    185         kotafilter.logger.log_message("%s" % msg, "warn") 
    186         counterbeforejob = None 
    187         printerIsOff = 1 
    188     else :     
    189         printerIsOff = 0 
     190    # Tries MAXTRIES times, sleeping two seconds each time, in case the printer is sleeping. 
     191    # This was seen with my Apple LaserWriter 16/600 PS which doesn't answer before having warmed up. 
     192    for i in range(MAXTRIES) : 
     193        try : 
     194            counterbeforejob = kotafilter.requester.getPrinterPageCounter(kotafilter.printerhostname) 
     195        except PyKotaRequesterError, msg : 
     196            # can't get actual page counter, assume printer is off or warming up 
     197            # log the message anyway. 
     198            kotafilter.logger.log_message("%s" % msg, "warn") 
     199            counterbeforejob = None 
     200            printerIsOff = 1 
     201        else :     
     202            # printer answered, it is on so we can exit the loop 
     203            printerIsOff = 0 
     204            kotafilter.logger.log_message("GOT PAGE COUNTER !", "warn") 
     205            break 
     206        time.sleep(TIMETOSLEEP)     
    190207         
    191208    # Get the last page counter and last username from the Quota Storage backend 
  • pykota/trunk/NEWS

    r960 r962  
    2222PyKota NEWS : 
    2323 
     24    - 1.05alpha1 : 
     25     
     26        - Extracting the printer's internal page counter is now 
     27          tried several times, waiting several seconds between 
     28          two tries. This lets the time to warm up for some printers  
     29          which don't answer when they are sleeping (my Apple  
     30          LaserWriter 16/600 PS is in this case, maybe others too) 
     31           
    2432    - 1.04 : 
    2533     
  • pykota/trunk/pykota/version.py

    r960 r962  
    2121# 
    2222 
    23 __version__ = "1.04-unofficial" 
     23__version__ = "1.05alpha1-unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""