Changeset 583
- Timestamp:
- 03/13/05 17:25:29 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
tea4cups/trunk/tea4cups
r582 r583 254 254 sectionbranches = [ (k, v) for (k, v) in self.config.items(printqueuename) if k.startswith("tee_") ] 255 255 except ConfigParser.NoSectionError, msg : 256 self.logInfo("No section for print queue %s : " % (printqueuename, msg), "info")256 self.logInfo("No section for print queue %s : %s" % (printqueuename, msg)) 257 257 sectionbranches = [] 258 258 branches = {} … … 351 351 fulldevice_uri = device_uri[:] 352 352 device_uri = fulldevice_uri[len(muststartwith):] 353 if device_uri.startswith("//") : 354 device_uri = device_uri[2:] 353 for i in range(2) : 354 if device_uri.startswith("/") : 355 device_uri = device_uri[1:] 355 356 try : 356 357 (backend, destination) = device_uri.split(":", 1) 357 358 except ValueError : 358 raise TeeError, "Invalid DEVICE_URI : %s\n" % device_uri 359 if not device_uri : 360 self.logInfo("Not attached to an existing print queue.") 361 backend = "" 362 else : 363 raise TeeError, "Invalid DEVICE_URI : %s\n" % device_uri 359 364 360 365 self.JobId = sys.argv[1].strip() … … 375 380 self.ClientHost = self.extractJobOriginatingHostName() 376 381 382 def getCupsConfigDirectives(self, directives=[]) : 383 """Retrieves some CUPS directives from its configuration file. 384 385 Returns a mapping with lowercased directives as keys and 386 their setting as values. 387 """ 388 dirvalues = {} 389 cupsroot = os.environ.get("CUPS_SERVERROOT", "/etc/cups") 390 cupsdconf = os.path.join(cupsroot, "cupsd.conf") 391 try : 392 conffile = open(cupsdconf, "r") 393 except IOError : 394 raise TeeError, "Unable to open %s" % cupsdconf 395 else : 396 for line in conffile.readlines() : 397 linecopy = line.strip().lower() 398 for di in [d.lower() for d in directives] : 399 if linecopy.startswith("%s " % di) : 400 try : 401 val = line.split()[1] 402 except : 403 pass # ignore errors, we take the last value in any case. 404 else : 405 dirvalues[di] = val 406 conffile.close() 407 return dirvalues 408 377 409 def extractJobOriginatingHostName(self) : 378 410 """Extracts the client's hostname or IP address from the CUPS message file for current job.""" 411 cupsdconf = self.getCupsConfigDirectives(["RequestRoot"]) 379 412 requestroot = cupsdconf.get("requestroot", "/var/spool/cups") 380 413 if (len(self.JobId) < 5) and self.JobId.isdigit() : … … 417 450 def saveDatasAndCheckSum(self) : 418 451 """Saves the input datas into a static file.""" 419 self.logDebug("Duplicating data stream to %s" % self.DataFile)452 self.logDebug("Duplicating data stream into %s" % self.DataFile) 420 453 mustclose = 0 421 454 if self.InputFile is not None :