Changeset 708 for pykota/trunk
- Timestamp:
- 02/06/03 00:26:22 (22 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/config.py
r707 r708 15 15 # 16 16 # $Log$ 17 # Revision 1.3 2003/02/05 23:26:22 jalet 18 # Incorrect handling of grace delay 19 # 17 20 # Revision 1.2 2003/02/05 23:09:20 jalet 18 21 # Name conflict … … 129 132 """Returns the full name of the Print Quota Administrator.""" 130 133 return self.config.get("global", "admin") 134 135 def getGraceDelay(self) : 136 """Returns the grace delay in days.""" 137 return int(self.config.get("global", "gracedelay")) -
pykota/trunk/pykota/storages/sql.py
r706 r708 15 15 # 16 16 # $Log$ 17 # Revision 1.5 2003/02/05 23:26:22 jalet 18 # Incorrect handling of grace delay 19 # 17 20 # Revision 1.4 2003/02/05 23:02:10 jalet 18 21 # Typo … … 30 33 # 31 34 # 32 33 from mx import DateTime34 35 35 36 class SQLStorage : … … 86 87 self.updateUserPQuota(username, printername, -pagebought) 87 88 88 def checkUserPQuota(self, username, printername) :89 # TODO : this doesn't work as expected wrt dates90 # TODO : GRACEDELAY should come from the configuration file91 # TODO : move this into the PyKotaTool class92 now = DateTime.now()93 quota = self.getUserPQuota(username, printername)94 pagecounter = quota["pagecounter"]95 softlimit = quota["softlimit"]96 hardlimit = quota["hardlimit"]97 datelimit = quota["datelimit"]98 if datelimit :99 datelimit = DateTime.DateTime(datelimit) # TODO : check this !100 if softlimit is not None :101 if pagecounter < softlimit :102 action = "ALLOW"103 elif hardlimit is not None :104 if softlimit <= pagecounter < hardlimit :105 if datelimit is None :106 self.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))))107 datelimit = now108 if (now - datelimit) <= GRACEDELAY :109 action = "WARN"110 else :111 action = "DENY"112 else :113 action = "DENY"114 else :115 action = "DENY"116 else :117 action = "ALLOW"118 return (action, (hardlimit - pagecounter), datelimit)119 -
pykota/trunk/pykota/tool.py
r699 r708 15 15 # 16 16 # $Log$ 17 # Revision 1.4 2003/02/05 23:26:22 jalet 18 # Incorrect handling of grace delay 19 # 17 20 # Revision 1.3 2003/02/05 22:16:20 jalet 18 21 # DEVICE_URI is undefined outside of CUPS, i.e. for normal command line tools … … 30 33 import os 31 34 import smtplib 35 36 from mx import DateTime 32 37 33 38 from pykota import config … … 73 78 self.sendMessage(self.adminmail, "Subject: %s\n\n%s" % (subject, message)) 74 79 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 75 110 def warnQuotaPrinter(self, username) : 76 111 """Checks a user quota and send him a message if quota is exceeded on current printer."""