- Timestamp:
- 11/06/04 23:35:58 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 1 added
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1897 r1901 24 24 # 25 25 # $Log$ 26 # Revision 1.76 2004/11/06 22:35:58 jalet 27 # Added a miniparser for IPP messages (RFC 2910). The job-originating-host-name 28 # retrieval is now fiable, unless the CUPS developpers change something... 29 # 26 30 # Revision 1.75 2004/11/01 15:45:25 jalet 27 31 # Added many debug messages. … … 299 303 from pykota.storage import PyKotaStorageError 300 304 from pykota.accounter import PyKotaAccounterError 305 from pykota.ipp import IPPMessage, PyKotaIPPError 301 306 302 307 class PyKotaPopen4(popen2.Popen4) : … … 338 343 return 0 339 344 340 def get PageLogLocation(self) :341 """Retrieves CUPS' page_log file location."""342 location = None345 def getCupsConfigDirectives(self, directives=[]) : 346 """Retrieves some CUPS directives from its configuration file.""" 347 dirvalues = {} 343 348 cupsroot = os.environ.get("CUPS_SERVERROOT", "/etc/cups") 344 349 cupsdconf = os.path.join(cupsroot, "cupsd.conf") … … 347 352 except IOError : 348 353 self.logdebug("Unable to open %s" % cupsdconf) 349 return # file doesn't exist or can't be read350 354 else : 351 355 for line in conffile.readlines() : 352 356 linecopy = line.strip().lower() 353 if linecopy.startswith("pagelog ") : 354 try : 355 location = line.split()[1] 356 except : 357 pass # ignore errors, we take the last value in any case. 357 for di in [d.lower() for d in directives] : 358 if linecopy.startswith("%s " % di) : 359 try : 360 val = line.split()[1] 361 except : 362 pass # ignore errors, we take the last value in any case. 363 else : 364 dirvalues[di] = val 358 365 conffile.close() 359 return location360 361 def getJobOriginatingHostname (self, printername, username, jobid) :366 return dirvalues 367 368 def getJobOriginatingHostnameFromPageLog(self, cupsconfig, printername, username, jobid) : 362 369 """Retrieves the job-originating-hostname from the CUPS page_log file if possible.""" 363 pagelogpath = self.getPageLogLocation() or "/var/log/cups/page_log" 370 pagelogpath = cupsconfig.get("pagelog", "/var/log/cups/page_log") 371 self.logdebug("Trying to extract job-originating-host-name from %s" % pagelogpath) 364 372 try : 365 373 pagelog = open(pagelogpath, "r") … … 383 391 if matchingline is None : 384 392 self.logdebug("No matching line found in %s" % pagelogpath) 385 return # correct line not found, job-originating-host name unknown393 return # correct line not found, job-originating-host-name unknown 386 394 else : 387 395 return matchingline.split()[-1] … … 398 406 self.exportUserInfo(userpquota) 399 407 400 # tries to extract job-originating-hostname 401 clienthost = self.getJobOriginatingHostname(printer.Name, user.Name, self.jobid) 408 # tries to extract job-originating-host-name and other information 409 cupsdconf = self.getCupsConfigDirectives(["PageLog", "RequestRoot"]) 410 requestroot = cupsdconf.get("requestroot", "/var/spool/cups") 411 if (len(self.jobid) < 5) and self.jobid.isdigit() : 412 ippmessagefile = "c%05i" % int(self.jobid) 413 else : 414 ippmessagefile = "c%s" % self.jobid 415 ippmessagefile = os.path.join(requestroot, ippmessagefile) 416 ippmessage = {} 417 try : 418 ippdatafile = open(ippmessagefile) 419 except : 420 self.printInfo("Unable to open IPP message file %s" % ippmessagefile, "warn") 421 else : 422 self.logdebug("Parsing of IPP message file %s begins." % ippmessagefile) 423 ippmessage = IPPMessage(ippdatafile.read()) 424 self.logdebug("Parsing of IPP message file %s ends." % ippmessagefile) 425 ippdatafile.close() 426 427 clienthost = ippmessage.get("job-originating-host-name") \ 428 or self.getJobOriginatingHostnameFromPageLog(cupsdconf, printer.Name, user.Name, self.jobid) 402 429 self.logdebug("Client Hostname : %s" % (clienthost or "Unknown")) 403 430 os.environ["PYKOTAJOBORIGINATINGHOSTNAME"] = str(clienthost or "") 431 432 # TODO : extract username (double check ?) and billing code too 404 433 405 434 # enters first phase -
pykota/trunk/NEWS
r1894 r1901 22 22 PyKota NEWS : 23 23 24 - 1.21alpha1 : 25 26 - added an IPP messages miniparser. This will allow PyKota 27 to extract informations from the CUPS request files directly 28 without needing to use the CUPS API. 29 24 30 - 1.20 : 25 31 -
pykota/trunk/pykota/version.py
r1894 r1901 22 22 # 23 23 24 __version__ = "1.2 0_unofficial"24 __version__ = "1.21alpha1_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""