Show
Ignore:
Timestamp:
05/25/04 00:45:49 (20 years ago)
Author:
jalet
Message:

New 'enforcement' directive added
Polling loop improvements

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r1492 r1495  
    2222# 
    2323# $Log$ 
     24# Revision 1.90  2004/05/24 22:45:49  jalet 
     25# New 'enforcement' directive added 
     26# Polling loop improvements 
     27# 
    2428# Revision 1.89  2004/05/21 22:02:52  jalet 
    2529# Preliminary work on pre-accounting 
     
    379383        self.smtpserver = self.config.getSMTPServer() 
    380384        self.maildomain = self.config.getMailDomain() 
     385        self.softwareJobPrice = 0.0 
    381386         
    382387    def logdebug(self, message) :     
     
    513518        user = userpquota.User 
    514519        printer = userpquota.Printer 
     520        enforcement = self.config.getPrinterEnforcement(printer.Name) 
    515521        self.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) 
    516522        (policy, dummy) = self.config.getPrinterPolicy(userpquota.Printer.Name) 
     
    524530        else :     
    525531            pagecounter = int(userpquota.PageCounter or 0) 
     532            if enforcement == "STRICT" : 
     533                pagecounter += self.softwareJobSize 
    526534            if userpquota.SoftLimit is not None : 
    527535                softlimit = int(userpquota.SoftLimit) 
     
    564572        group = grouppquota.Group 
    565573        printer = grouppquota.Printer 
     574        enforcement = self.config.getPrinterEnforcement(printer.Name) 
    566575        self.logdebug("Checking group %s's quota on printer %s" % (group.Name, printer.Name)) 
    567576        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 : 
    569581                action = "DENY" 
    570             elif group.AccountBalance <= self.config.getPoorMan() :     
     582            elif val <= self.config.getPoorMan() :     
    571583                action = "WARN" 
    572584            else :     
    573585                action = "ALLOW" 
    574586        else : 
     587            val = grouppquota.PageCounter 
     588            if enforcement == "STRICT" : 
     589                val += self.softwareJobSize 
    575590            if grouppquota.SoftLimit is not None : 
    576591                softlimit = int(grouppquota.SoftLimit) 
    577                 if grouppquota.PageCounter < softlimit : 
     592                if val < softlimit : 
    578593                    action = "ALLOW" 
    579594                else :     
     
    583598                    else :     
    584599                        hardlimit = int(grouppquota.HardLimit) 
    585                         if softlimit <= grouppquota.PageCounter < hardlimit :     
     600                        if softlimit <= val < hardlimit :     
    586601                            now = DateTime.now() 
    587602                            if grouppquota.DateLimit is not None : 
     
    600615                    # no soft limit, only a hard one. 
    601616                    hardlimit = int(grouppquota.HardLimit) 
    602                     if grouppquota.PageCounter < hardlimit : 
     617                    if val < hardlimit : 
    603618                        action = "ALLOW" 
    604619                    else :       
     
    643658            else :     
    644659                val = float(user.AccountBalance or 0.0) 
     660                if self.config.getPrinterEnforcement(printer.Name) == "STRICT" :  
     661                    val -= self.softwareJobPrice # use precomputed size. 
    645662                if val <= 0.0 : 
    646663                    return "DENY" 
     
    820837    def precomputeJobSize(self) :     
    821838        """Computes the job size with a software method.""" 
     839        self.logdebug("Precomputing job's size with generic PDL analyzer...") 
    822840        try : 
    823841            parser = pdlanalyzer.PDLAnalyzer(self.jobdatastream) 
    824             return parser.getJobSize() 
     842            jobsize = parser.getJobSize() 
    825843        except pdlanalyzer.PDLAnalyzerError, msg :     
    826844            # Here we just log the failure, but 
     
    830848            self.logger.log_message(_("Unable to precompute the job's size with the generic PDL analyzer."), "warn") 
    831849            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 
    832857             
    833858    def sigterm_handler(self, signum, frame) :