Changeset 962 for pykota/trunk/bin
- Timestamp:
- 04/25/03 10:23:23 (22 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pykota
r956 r962 23 23 # 24 24 # $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 # 25 29 # Revision 1.25 2003/04/24 11:53:48 jalet 26 30 # Default policy for unknown users/groups is to DENY printing instead … … 119 123 import sys 120 124 import os 125 import time 121 126 122 127 from pykota.tool import PyKotaTool, PyKotaToolError 123 128 from pykota.requester import openRequester, PyKotaRequesterError 129 130 MAXTRIES = 6 # maximum number of tries to get the printer's internal page counter 131 TIMETOSLEEP = 10 # number of seconds to sleep between two tries to get the printer's internal page counter 124 132 125 133 class PyKotaFilter(PyKotaTool) : … … 167 175 def main() : 168 176 """Do it, and do it right !""" 169 177 global MAXTRIES, TIMETOSLEEP 178 170 179 # Initializes the current tool 171 180 kotafilter = PyKotaFilter() … … 179 188 180 189 # 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) 190 207 191 208 # Get the last page counter and last username from the Quota Storage backend