| 384 | |
| 385 | def genBanner(self, bannerfileorcommand) : |
| 386 | """Reads a banner or generates one through an external command. |
| 387 | |
| 388 | Returns the banner's content in a format which MUST be accepted |
| 389 | by the printer. |
| 390 | """ |
| 391 | if bannerfileorcommand : |
| 392 | banner = "" # no banner by default |
| 393 | if os.access(bannerfileorcommand, os.X_OK) or not os.path.isfile(bannerfileorcommand) : |
| 394 | self.logdebug("Launching %s to generate a banner." % bannerfileorcommand) |
| 395 | child = popen2.Popen3(bannerfileorcommand, capturestderr=1) |
| 396 | banner = child.fromchild.read() |
| 397 | child.tochild.close() |
| 398 | child.childerr.close() |
| 399 | child.fromchild.close() |
| 400 | status = child.wait() |
| 401 | if os.WIFEXITED(status) : |
| 402 | status = os.WEXITSTATUS(status) |
| 403 | self.printInfo(_("Banner generator %s exit code is %s") % (bannerfileorcommand, str(status))) |
| 404 | else : |
| 405 | self.logdebug("Using %s as the banner." % bannerfileorcommand) |
| 406 | try : |
| 407 | fh = open(bannerfileorcommand, 'r') |
| 408 | except IOError, msg : |
| 409 | self.printInfo("Impossible to open %s : %s" % (bannerfileorcommand, msg), "error") |
| 410 | else : |
| 411 | banner = fh.read() |
| 412 | fh.close() |
| 413 | if banner : |
| 414 | return cStringIO.StringIO(banner) |
| 415 | |
| 416 | def startingBanner(self, printername) : |
| 417 | """Retrieves a starting banner for current printer and returns its content.""" |
| 418 | self.logdebug("Retrieving starting banner...") |
| 419 | return self.genBanner(self.config.getStartingBanner(printername)) |
| 420 | |
| 421 | def endingBanner(self, printername) : |
| 422 | """Retrieves an ending banner for current printer and returns its content.""" |
| 423 | self.logdebug("Retrieving ending banner...") |
| 424 | return self.genBanner(self.config.getEndingBanner(printername)) |
482 | | # do we want strict or laxist quota enforcement ? |
483 | | if self.config.getPrinterEnforcement(printer.Name) == "STRICT" : |
484 | | self.softwareJobSize = self.precomputeJobSize() |
485 | | self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) |
486 | | self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) |
487 | | os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) |
| 527 | # precomputes the job's price |
| 528 | self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) |