Show
Ignore:
Timestamp:
02/06/03 00:26:22 (21 years ago)
Author:
jalet
Message:

Incorrect handling of grace delay

Files:
1 modified

Legend:

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

    r699 r708  
    1515# 
    1616# $Log$ 
     17# Revision 1.4  2003/02/05 23:26:22  jalet 
     18# Incorrect handling of grace delay 
     19# 
    1720# Revision 1.3  2003/02/05 22:16:20  jalet 
    1821# DEVICE_URI is undefined outside of CUPS, i.e. for normal command line tools 
     
    3033import os 
    3134import smtplib 
     35 
     36from mx import DateTime 
    3237 
    3338from pykota import config 
     
    7378        self.sendMessage(self.adminmail, "Subject: %s\n\n%s" % (subject, message)) 
    7479         
     80    def checkUserPQuota(self, username, printername) : 
     81        """Checks the user quota on a printer and deny or accept the job.""" 
     82        now = DateTime.now() 
     83        quota = self.storage.getUserPQuota(username, printername) 
     84        pagecounter = quota["pagecounter"] 
     85        softlimit = quota["softlimit"] 
     86        hardlimit = quota["hardlimit"] 
     87        datelimit = quota["datelimit"] 
     88        if datelimit : 
     89            datelimit = DateTime.DateTime(datelimit)    # TODO : check this ! 
     90        if softlimit is not None : 
     91            if pagecounter < softlimit : 
     92                action = "ALLOW" 
     93            elif hardlimit is not None : 
     94                 if softlimit <= pagecounter < hardlimit :     
     95                     if datelimit is None : 
     96                         self.storage.doQuery("UPDATE userpquota SET datelimit=%s::DATETIME WHERE userid=%s AND printerid=%s;" % (self.doQuote("%04i-%02i-%02i %02i:%02i" % (now.year, now.month, now.day, now.hour, now.minute)), self.doQuote(self.getUserId(username)), self.doQuote(self.getPrinterId(printername)))) 
     97                         datelimit = now 
     98                     if (now - datelimit) <= self.config.getGraceDelay() : 
     99                         action = "WARN" 
     100                     else :     
     101                         action = "DENY" 
     102                 else :          
     103                     action = "DENY" 
     104            else :         
     105                action = "DENY" 
     106        else :         
     107            action = "ALLOW" 
     108        return (action, (hardlimit - pagecounter), datelimit) 
     109     
    75110    def warnQuotaPrinter(self, username) : 
    76111        """Checks a user quota and send him a message if quota is exceeded on current printer."""