Changeset 2799
- Timestamp:
- 03/20/06 23:55:16 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pknotify
r2786 r2799 29 29 import popen2 30 30 import socket 31 import signal 31 32 import xmlrpclib 32 33 … … 73 74 or abortion. 74 75 76 -D | --denyafter N With --checkauth above, makes pknotify loop 77 up to N times if the password is incorrect. 78 After having reached the limit, "DENY" will 79 be printed, which effectively rejects the job. 80 The default value of N is 1, meaning the job 81 is denied after the first unsuccessful try. 82 75 83 -n | --notify Tells pknotify to send an informational message 76 84 message to the end user. … … 80 88 be combined with the other ones to make PyKotIcon 81 89 exit after having sent the answer from the dialog. 90 91 -t | --timeout T Tells pknotify to ignore the end user's answer if 92 it comes pas T seconds after the dialog box being 93 opened. The default value is 0 seconds, which 94 tells pknotify to wait indefinitely. 95 Use this option to avoid having an user who 96 leaved his computer stall a whole print queue. 82 97 83 98 You MUST specify either --ask, --confirm, --notify or --quit. … … 119 134 only set if you launch pknotify from cupspykota through a directive 120 135 in ~pykota/pykota.conf 136 137 The TCP port you'll use must be reachable on the client from the 138 print server. 121 139 """) 122 140 141 class TimeoutError(Exception) : 142 """An exception for timeouts.""" 143 def __init__(self, message = ""): 144 self.message = message 145 Exception.__init__(self, message) 146 def __repr__(self): 147 return self.message 148 __str__ = __repr__ 149 123 150 class PyKotaNotify(Tool) : 124 151 """A class for pknotify.""" … … 165 192 return retcode 166 193 194 def alarmHandler(self, signum, frame) : 195 """Alarm handler.""" 196 raise TimeoutError, "The end user at %s:%i didn't answer after %i seconds !" % (self.destination, self.port, self.timeout) 197 167 198 def main(self, arguments, options) : 168 199 """Notifies or asks questions to end users through PyKotIcon.""" 169 200 try : 170 (destination, port) = options["destination"].split(":") 201 (self.destination, self.port) = options["destination"].split(":") 202 self.port = int(self.port) 171 203 except ValueError : 172 destination = options["destination"] 173 port = 7654 204 self.destination = options["destination"] 205 self.port = 7654 206 207 try : 208 denyafter = int(options["denyafter"]) 209 if denyafter < 1 : 210 raise ValueError 211 except (ValueError, TypeError) : 212 denyafter = 1 213 174 214 try : 175 server = xmlrpclib.ServerProxy("http://%s:%s" % (destination, port)) 215 self.timeout = int(options["timeout"]) 216 if self.timeout < 0 : 217 raise ValueError 218 except (ValueError, TypeError) : 219 self.timeout = 0 220 221 if self.timeout : 222 signal.signal(signal.SIGALRM, self.alarmHandler) 223 signal.alarm(self.timeout) 224 225 try : 226 server = xmlrpclib.ServerProxy("http://%s:%s" % (self.destination, self.port)) 176 227 if options["ask"] : 177 228 labels = [] … … 200 251 for varname in varnames : 201 252 if (varname != "password") \ 202 and ((varname != "username") or (authok == "AUTH=YES")) :253 and ((varname != "username") or (authok in (None, "AUTH=YES"))) : 203 254 print "%s=%s" % (varname.upper(), result[varname].data) 204 255 if authok is not None : … … 213 264 except (socket.error, socket.gaierror), msg : 214 265 raise PyKotaCommandLineError, "%s : %s" % (_("Connection error"), str(msg)) 266 except TimeoutError, msg : 267 self.printInfo(msg, "warn") 268 269 if self.timeout : 270 signal.alarm(0) 215 271 216 272 if __name__ == "__main__" : … … 218 274 try : 219 275 defaults = { \ 276 "denyafter" : 1, 277 "timeout" : 0, 220 278 } 221 short_options = "vhd:acnqC" 222 long_options = ["help", "version", "destination=", \ 223 "ask", "checkauth", "confirm", "notify", "quit" ] 279 short_options = "vhd:acnqCD:t:" 280 long_options = ["help", "version", "destination=", "denyafter=", \ 281 "timeout=", "ask", "checkauth", "confirm", "notify", \ 282 "quit" ] 224 283 225 284 # Initializes the command line tool … … 239 298 options["quit"] = options["q"] or options["quit"] 240 299 options["checkauth"] = options["C"] or options["checkauth"] 300 options["denyafter"] = options["D"] or options["denyafter"] or defaults["denyafter"] 301 options["timeout"] = options["t"] or options["timeout"] or defaults["timeout"] 241 302 242 303 if options["help"] : … … 246 307 elif (options["ask"] and (options["confirm"] or options["notify"])) \ 247 308 or (options["confirm"] and (options["ask"] or options["notify"])) \ 248 or ( options["checkauth"]and not options["ask"]) \309 or ((options["checkauth"] or options["denyafter"]) and not options["ask"]) \ 249 310 or (options["notify"] and (options["ask"] or options["confirm"])) : 250 311 raise PyKotaCommandLineError, _("incompatible options, see help.")