Changeset 1495 for pykota/trunk/pykota/tool.py
- Timestamp:
- 05/25/04 00:45:49 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/tool.py
r1492 r1495 22 22 # 23 23 # $Log$ 24 # Revision 1.90 2004/05/24 22:45:49 jalet 25 # New 'enforcement' directive added 26 # Polling loop improvements 27 # 24 28 # Revision 1.89 2004/05/21 22:02:52 jalet 25 29 # Preliminary work on pre-accounting … … 379 383 self.smtpserver = self.config.getSMTPServer() 380 384 self.maildomain = self.config.getMailDomain() 385 self.softwareJobPrice = 0.0 381 386 382 387 def logdebug(self, message) : … … 513 518 user = userpquota.User 514 519 printer = userpquota.Printer 520 enforcement = self.config.getPrinterEnforcement(printer.Name) 515 521 self.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) 516 522 (policy, dummy) = self.config.getPrinterPolicy(userpquota.Printer.Name) … … 524 530 else : 525 531 pagecounter = int(userpquota.PageCounter or 0) 532 if enforcement == "STRICT" : 533 pagecounter += self.softwareJobSize 526 534 if userpquota.SoftLimit is not None : 527 535 softlimit = int(userpquota.SoftLimit) … … 564 572 group = grouppquota.Group 565 573 printer = grouppquota.Printer 574 enforcement = self.config.getPrinterEnforcement(printer.Name) 566 575 self.logdebug("Checking group %s's quota on printer %s" % (group.Name, printer.Name)) 567 576 if group.LimitBy and (group.LimitBy.lower() == "balance") : 568 if group.AccountBalance <= 0.0 : 577 val = group.AccountBalance 578 if enforcement == "STRICT" : 579 val -= self.softwareJobPrice # use precomputed size. 580 if val <= 0.0 : 569 581 action = "DENY" 570 elif group.AccountBalance<= self.config.getPoorMan() :582 elif val <= self.config.getPoorMan() : 571 583 action = "WARN" 572 584 else : 573 585 action = "ALLOW" 574 586 else : 587 val = grouppquota.PageCounter 588 if enforcement == "STRICT" : 589 val += self.softwareJobSize 575 590 if grouppquota.SoftLimit is not None : 576 591 softlimit = int(grouppquota.SoftLimit) 577 if grouppquota.PageCounter< softlimit :592 if val < softlimit : 578 593 action = "ALLOW" 579 594 else : … … 583 598 else : 584 599 hardlimit = int(grouppquota.HardLimit) 585 if softlimit <= grouppquota.PageCounter< hardlimit :600 if softlimit <= val < hardlimit : 586 601 now = DateTime.now() 587 602 if grouppquota.DateLimit is not None : … … 600 615 # no soft limit, only a hard one. 601 616 hardlimit = int(grouppquota.HardLimit) 602 if grouppquota.PageCounter< hardlimit :617 if val < hardlimit : 603 618 action = "ALLOW" 604 619 else : … … 643 658 else : 644 659 val = float(user.AccountBalance or 0.0) 660 if self.config.getPrinterEnforcement(printer.Name) == "STRICT" : 661 val -= self.softwareJobPrice # use precomputed size. 645 662 if val <= 0.0 : 646 663 return "DENY" … … 820 837 def precomputeJobSize(self) : 821 838 """Computes the job size with a software method.""" 839 self.logdebug("Precomputing job's size with generic PDL analyzer...") 822 840 try : 823 841 parser = pdlanalyzer.PDLAnalyzer(self.jobdatastream) 824 returnparser.getJobSize()842 jobsize = parser.getJobSize() 825 843 except pdlanalyzer.PDLAnalyzerError, msg : 826 844 # Here we just log the failure, but … … 830 848 self.logger.log_message(_("Unable to precompute the job's size with the generic PDL analyzer."), "warn") 831 849 return 0 850 else : 851 if ((self.printingsystem == "CUPS") \ 852 and (self.preserveinputfile is not None)) \ 853 or (self.printingsystem != "CUPS") : 854 return jobsize * self.copies 855 else : 856 return jobsize 832 857 833 858 def sigterm_handler(self, signum, frame) :