- Timestamp:
- 03/13/05 15:30:22 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r581 r582 33 33 from struct import unpack 34 34 35 OPERATION_ATTRIBUTES_TAG = 0x0136 JOB_ATTRIBUTES_TAG = 0x0237 END_OF_ATTRIBUTES_TAG = 0x0338 PRINTER_ATTRIBUTES_TAG = 0x0439 UNSUPPORTED_ATTRIBUTES_TAG = 0x0540 41 35 class TeeError(Exception): 42 36 """Base exception for Tea4CUPS related stuff.""" … … 56 50 pass 57 51 52 # Some IPP constants 53 OPERATION_ATTRIBUTES_TAG = 0x01 54 JOB_ATTRIBUTES_TAG = 0x02 55 END_OF_ATTRIBUTES_TAG = 0x03 56 PRINTER_ATTRIBUTES_TAG = 0x04 57 UNSUPPORTED_ATTRIBUTES_TAG = 0x05 58 58 59 class IPPMessage : 59 60 """A class for IPP message files.""" … … 372 373 self.Directory = self.getPrintQueueOption(self.PrinterName, "directory") 373 374 self.DataFile = os.path.join(self.Directory, "%s-%s-%s-%s" % (self.myname, self.PrinterName, self.UserName, self.JobId)) 374 375 self.ClientHost = self.extractJobOriginatingHostName() 376 377 def extractJobOriginatingHostName(self) : 378 """Extracts the client's hostname or IP address from the CUPS message file for current job.""" 379 requestroot = cupsdconf.get("requestroot", "/var/spool/cups") 380 if (len(self.JobId) < 5) and self.JobId.isdigit() : 381 ippmessagefile = "c%05i" % int(self.JobId) 382 else : 383 ippmessagefile = "c%s" % self.JobId 384 ippmessagefile = os.path.join(requestroot, ippmessagefile) 385 ippmessage = {} 386 try : 387 ippdatafile = open(ippmessagefile) 388 except : 389 self.logInfo("Unable to open IPP message file %s" % ippmessagefile, "warn") 390 else : 391 self.logDebug("Parsing of IPP message file %s begins." % ippmessagefile) 392 try : 393 ippmessage = IPPMessage(ippdatafile.read()) 394 except IPPError, msg : 395 self.logInfo("Error while parsing %s : %s" % (ippmessagefile, msg), "warn") 396 else : 397 self.logDebug("Parsing of IPP message file %s ends." % ippmessagefile) 398 ippdatafile.close() 399 return ippmessage.get("job-originating-host-name") 400 375 401 def exportAttributes(self) : 376 402 """Exports our backend's attributes to the environment.""" … … 381 407 os.environ["TEAJOBSIZE"] = str(self.JobSize) 382 408 os.environ["TEAMD5SUM"] = self.JobMD5Sum 409 os.environ["TEACLIENTHOST"] = self.ClientHost or "" 383 410 os.environ["TEAJOBID"] = self.JobId 384 411 os.environ["TEAUSERNAME"] = self.UserName