Changeset 2060
- Timestamp:
- 02/14/05 23:53:44 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r2057 r2060 24 24 # 25 25 # $Log$ 26 # Revision 1.87 2005/02/14 22:53:44 jalet 27 # Now always precomputes the job's size with the internal PDL parser, and not 28 # only when 'enforcement: strict' was set in pykota.conf 29 # 26 30 # Revision 1.86 2005/02/13 22:48:37 jalet 27 31 # Added the md5sum to the history … … 378 382 """ 379 383 return 0 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)) 380 425 381 426 def getCupsConfigDirectives(self, directives=[]) : … … 480 525 os.environ["PYKOTAPHASE"] = "BEFORE" 481 526 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) 488 529 os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) 530 self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 489 531 490 532 # if no data to pass to real backend, probably a filter -
pykota/trunk/bin/lprngpykota
r2057 r2060 24 24 # 25 25 # $Log$ 26 # Revision 1.15 2005/02/14 22:53:44 jalet 27 # Now always precomputes the job's size with the internal PDL parser, and not 28 # only when 'enforcement: strict' was set in pykota.conf 29 # 26 30 # Revision 1.14 2005/02/13 22:48:37 jalet 27 31 # Added the md5sum to the history … … 137 141 os.environ["PYKOTAPHASE"] = "BEFORE" 138 142 139 # do we want strict or laxist quota enforcement ? 140 if self.config.getPrinterEnforcement(printer.Name) == "STRICT" : 141 self.softwareJobSize = self.precomputeJobSize() 142 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 143 self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 144 os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 143 # precomputes the job's price 144 self.softwareJobPrice = userpquota.computeJobPrice(self.softwareJobSize) 145 145 os.environ["PYKOTAPRECOMPUTEDJOBPRICE"] = str(self.softwareJobPrice) 146 self.logdebug("Precomputed job's size is %s pages, price is %s units" % (self.softwareJobSize, self.softwareJobPrice)) 146 147 147 148 # if no data to pass to real backend, probably a filter … … 251 252 # retrieve the job size 252 253 jobsize = self.accounter.getJobSize(printer) 254 if self.softwareJobSize and (jobsize != self.softwareJobSize) : 255 self.printInfo(_("Beware : computed job size (%s) != precomputed job size (%s)") % (jobsize, self.softwareJobSize), "error") 253 256 254 257 self.printMoreInfo(user, printer, _("Job size : %i") % jobsize) -
pykota/trunk/pykota/tool.py
r2054 r2060 22 22 # 23 23 # $Log$ 24 # Revision 1.150 2005/02/14 22:53:44 jalet 25 # Now always precomputes the job's size with the internal PDL parser, and not 26 # only when 'enforcement: strict' was set in pykota.conf 27 # 24 28 # Revision 1.149 2005/02/13 22:02:29 jalet 25 29 # Big database structure changes. Upgrade script is now included as well as … … 1190 1194 self.jobdatastream = self.openJobDataStream() 1191 1195 self.checksum = self.computeChecksum() 1196 self.softwareJobSize = self.precomputeJobSize() 1197 os.environ["PYKOTAPRECOMPUTEDJOBSIZE"] = str(self.softwareJobSize) 1192 1198 os.environ["PYKOTAJOBSIZEBYTES"] = str(self.jobSizeBytes) 1193 self.logdebug("Job size is %s bytes " % self.jobSizeBytes)1199 self.logdebug("Job size is %s bytes on %s pages." % (self.jobSizeBytes, self.softwareJobSize)) 1194 1200 self.logdebug("Capturing SIGTERM events.") 1195 1201 signal.signal(signal.SIGTERM, self.sigterm_handler) … … 1327 1333 self.logdebug("Executing post-hook [%s]" % posthook) 1328 1334 os.system(posthook) 1329 1330 def genBanner(self, bannerfileorcommand) : 1331 """Reads a banner or generates one through an external command. 1332 1333 Returns the banner's content in a format which MUST be accepted 1334 by the printer. 1335 """ 1336 if bannerfileorcommand : 1337 banner = "" # no banner by default 1338 if os.access(bannerfileorcommand, os.X_OK) or not os.path.isfile(bannerfileorcommand) : 1339 self.logdebug("Launching %s to generate a banner." % bannerfileorcommand) 1340 child = popen2.Popen3(bannerfileorcommand, capturestderr=1) 1341 banner = child.fromchild.read() 1342 child.tochild.close() 1343 child.childerr.close() 1344 child.fromchild.close() 1345 status = child.wait() 1346 if os.WIFEXITED(status) : 1347 status = os.WEXITSTATUS(status) 1348 self.printInfo(_("Banner generator %s exit code is %s") % (bannerfileorcommand, str(status))) 1349 else : 1350 self.logdebug("Using %s as the banner." % bannerfileorcommand) 1351 try : 1352 fh = open(bannerfileorcommand, 'r') 1353 except IOError, msg : 1354 self.printInfo("Impossible to open %s : %s" % (bannerfileorcommand, msg), "error") 1355 else : 1356 banner = fh.read() 1357 fh.close() 1358 if banner : 1359 return cStringIO.StringIO(banner) 1360 1361 def startingBanner(self, printername) : 1362 """Retrieves a starting banner for current printer and returns its content.""" 1363 self.logdebug("Retrieving starting banner...") 1364 return self.genBanner(self.config.getStartingBanner(printername)) 1365 1366 def endingBanner(self, printername) : 1367 """Retrieves an ending banner for current printer and returns its content.""" 1368 self.logdebug("Retrieving ending banner...") 1369 return self.genBanner(self.config.getEndingBanner(printername)) 1370 1335 1371 1336 def printInfo(self, message, level="info") : 1372 1337 """Sends a message to standard error."""