Changeset 2054 for pykota/trunk/pykota
- Timestamp:
- 02/13/05 23:02:29 (19 years ago)
- Location:
- pykota/trunk/pykota
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/config.py
r1968 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.59 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.58 2004/12/02 22:01:58 jalet 25 32 # TLS is now supported with the LDAP backend … … 507 514 return (mailto, args) 508 515 516 def getMaxDenyBanners(self, printername) : 517 """Returns the maximum number of deny banners to be printed for a particular user on a particular printer.""" 518 try : 519 maxdb = self.getPrinterOption(printername, "maxdenybanners") 520 except PyKotaConfigError : 521 return 0 # default value is to forbid printing a deny banner. 522 try : 523 value = int(maxdb.strip()) 524 if value < 0 : 525 raise ValueError 526 except (TypeError, ValueError) : 527 raise PyKotaConfigError, _("Invalid maximal deny banners counter %s") % maxdb 528 else : 529 return value 530 509 531 def getGraceDelay(self, printername) : 510 532 """Returns the grace delay in days.""" -
pykota/trunk/pykota/reporter.py
r1692 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.11 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.10 2004/09/02 10:09:30 jalet 25 32 # Fixed bug in LDAP user deletion code which didn't correctly delete the user's … … 87 94 def getReportHeader(self) : 88 95 if self.isgroup : 89 return _("Group used soft hard balance grace total paid")96 return _("Group overcharge used soft hard balance grace total paid warn") 90 97 else : 91 return _("User used soft hard balance grace total paid")98 return _("User overcharge used soft hard balance grace total paid warn") 92 99 93 100 def getPrinterRealPageCounter(self, printer) : … … 109 116 balance = float(entry.AccountBalance or 0.0) 110 117 lifetimepaid = float(entry.LifeTimePaid or 0.0) 118 if not hasattr(entry, "OverCharge") : 119 overcharge = _("N/A") # Not available for groups 120 else : 121 overcharge = float(entry.OverCharge or 0.0) 122 if not hasattr(quota, "WarnCount") : 123 warncount = _("N/A") # Not available for groups 124 else : 125 warncount = int(quota.WarnCount or 0) 111 126 112 127 #balance … … 199 214 strbalance = ("%5.2f" % balance)[:10] 200 215 strlifetimepaid = ("%6.2f" % lifetimepaid)[:10] 201 return (lifepagecounter, lifetimepaid, entry.Name, reached, pagecounter, str(quota.SoftLimit), str(quota.HardLimit), strbalance, str(datelimit)[:10], lifepagecounter, strlifetimepaid) 216 strovercharge = ("%5s" % overcharge)[:5] 217 strwarncount = ("%4s" % warncount)[:4] 218 return (lifepagecounter, lifetimepaid, entry.Name, reached, \ 219 pagecounter, str(quota.SoftLimit), str(quota.HardLimit), \ 220 strbalance, str(datelimit)[:10], lifepagecounter, \ 221 strlifetimepaid, strovercharge, strwarncount) 202 222 203 223 def openReporter(tool, reporttype, printers, ugnames, isgroup) : -
pykota/trunk/pykota/reporters/html.py
r1278 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.9 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.8 2004/01/12 15:28:45 jalet 25 32 # Now can output the user's history on several printers at the same time. … … 81 88 else : 82 89 oddevenclass = "even" 83 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid ) = self.getQuota(entry, entrypquota)90 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota) 84 91 if datelimit : 85 92 if datelimit == "DENY" : … … 89 96 if (not self.tool.config.getDisableHistory()) and (not self.isgroup) : 90 97 name = '<a href="%s?username=%s&printername=%s&history=1">%s</a>' % (os.environ.get("SCRIPT_NAME", ""), name, printer.Name, name) 91 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid)])))98 self.report.append('<tr class="%s">%s</tr>' % (oddevenclass, "".join(["<td>%s</td>" % h for h in (name, reached, overcharge, pagecounter, soft, hard, balance, datelimit or " ", lifepagecounter, lifetimepaid, warncount)]))) 92 99 total += pages 93 100 totalmoney += money … … 95 102 if total or totalmoney : 96 103 (tpage, tmoney) = self.getTotals(total, totalmoney) 97 self.report.append('<tr class="totals"><td colspan=" 7"> </td><td align="right">%s</td><td align="right">%s</td></tr>' % (tpage, tmoney))98 self.report.append('<tr class="realpagecounter"><td colspan=" 7"> </td><td align="right">%s</td></tr>' % self.getPrinterRealPageCounter(printer))104 self.report.append('<tr class="totals"><td colspan="8"> </td><td align="right">%s</td><td align="right">%s</td><td> </td></tr>' % (tpage, tmoney)) 105 self.report.append('<tr class="realpagecounter"><td colspan="8"> </td><td align="right">%s</td><td> </td></tr>' % self.getPrinterRealPageCounter(printer)) 99 106 self.report.append('</table>') 100 107 if self.isgroup : -
pykota/trunk/pykota/reporters/text.py
r1257 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.10 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.9 2004/01/08 14:10:33 jalet 25 32 # Copyright year changed. … … 78 85 self.report.append('-' * len(header)) 79 86 for (entry, entrypquota) in getattr(self.tool.storage, "getPrinter%ssAndQuotas" % prefix)(printer, self.ugnames) : 80 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid ) = self.getQuota(entry, entrypquota)81 self.report.append("%- 9.9s %s %7i %7s %7s %10s %-10.10s %8i %10s" % (name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid))87 (pages, money, name, reached, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, overcharge, warncount) = self.getQuota(entry, entrypquota) 88 self.report.append("%-15.15s %s %5s %7i %7s %7s %10s %-10.10s %8i %10s %4s" % (name, reached, overcharge, pagecounter, soft, hard, balance, datelimit, lifepagecounter, lifetimepaid, warncount)) 82 89 total += pages 83 90 totalmoney += money … … 85 92 if total or totalmoney : 86 93 (tpage, tmoney) = self.getTotals(total, totalmoney) 87 self.report.append((" " * 50) + tpage + tmoney)88 self.report.append((" " * 51) + self.getPrinterRealPageCounter(printer))94 self.report.append((" " * 62) + tpage + tmoney) 95 self.report.append((" " * 63) + self.getPrinterRealPageCounter(printer)) 89 96 self.report.append("") 90 97 if self.isgroup : -
pykota/trunk/pykota/storage.py
r2030 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.68 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.67 2005/01/18 19:47:50 jalet 25 32 # Big bug fix wrt the datelimit attribute … … 276 283 self.LifeTimePaid = None 277 284 self.Email = None 285 self.OverCharge = 1.0 278 286 self.Payments = [] # TODO : maybe handle this smartly for SQL, for now just don't retrieve them 279 287 … … 308 316 self.LimitBy = limitby 309 317 318 def setOverChargeFactor(self, factor) : 319 """Sets the user's overcharging coefficient.""" 320 self.parent.writeUserOverCharge(self, factor) 321 self.OverCharge = factor 322 310 323 def delete(self) : 311 324 """Deletes an user from the Quota Storage.""" … … 357 370 self.PricePerJob = None 358 371 self.Description = None 372 self.Coefficients = None 359 373 360 374 def __getattr__(self, name) : … … 424 438 self.HardLimit = None 425 439 self.DateLimit = None 440 self.WarnCount = None 426 441 427 442 def __getattr__(self, name) : … … 445 460 self.HardLimit = hardlimit 446 461 self.DateLimit = None 462 self.WarnCount = 0 447 463 448 464 def setUsage(self, used) : … … 454 470 self.parent.increaseUserPQuotaPagesCounters(self, vused) 455 471 self.parent.writeUserPQuotaDateLimit(self, None) 472 self.parent.writeUserPQuotaWarnCount(self, 0) 456 473 except PyKotaStorageError, msg : 457 474 self.parent.rollbackTransaction() … … 465 482 self.PageCounter = self.LifePageCounter = vused 466 483 self.DateLimit = None 484 self.WarnCount = 0 467 485 486 def warn(self) : 487 """Increases the warn counter for this user quota.""" 488 self.parent.increaseUserPQuotaWarnCount(self) 489 self.WarnCount = (self.WarnCount or 0) + 1 490 468 491 def reset(self) : 469 492 """Resets page counter to 0.""" … … 482 505 totalprice = 0.0 483 506 if jobsize : 484 for upq in [ self ] + self.ParentPrintersUserPQuota : 485 price = (float(upq.Printer.PricePerPage or 0.0) * jobsize) + float(upq.Printer.PricePerJob or 0.0) 486 totalprice += price 487 return totalprice 507 if self.User.OverCharge != 0.0 : # optimization, but TODO : beware of rounding errors 508 for upq in [ self ] + self.ParentPrintersUserPQuota : 509 price = (float(upq.Printer.PricePerPage or 0.0) * jobsize) + float(upq.Printer.PricePerJob or 0.0) 510 totalprice += price 511 if self.User.OverCharge != 1.0 : # TODO : beware of rounding errors 512 overcharged = totalprice * self.User.OverCharge 513 self.parent.tool.printInfo("Overcharging %s by a factor of %s ===> User %s will be charged for %s units." % (totalprice, self.User.OverCharge, self.User.Name, overcharged)) 514 return overcharged 515 else : 516 return totalprice 488 517 489 518 def increasePagesUsage(self, jobsize) : … … 589 618 self.JobOptions = None 590 619 self.JobHostName = None 620 self.JobMD5Sum = None 621 self.JobPages = None 622 self.JobBillingCode = None 591 623 592 624 def __getattr__(self, name) : -
pykota/trunk/pykota/storages/ldapstorage.py
r2042 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.100 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.99 2005/01/24 17:44:17 jalet 25 32 # Same fix for group print quota entries wrt LDAP performance … … 647 654 """Extracts user information given its name.""" 648 655 user = StorageUser(self, username) 649 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"] ], base=self.info["userbase"])656 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "pykotaOverCharge"], base=self.info["userbase"]) 650 657 if result : 651 658 fields = result[0][1] 652 659 user.ident = result[0][0] 653 660 user.Name = fields.get("pykotaUserName", [username])[0] 654 user.Email = fields.get(self.info["usermail"]) 655 if user.Email is not None : 656 user.Email = user.Email[0] 657 user.LimitBy = fields.get("pykotaLimitBy") 658 if user.LimitBy is not None : 659 user.LimitBy = user.LimitBy[0] 660 else : 661 user.LimitBy = "quota" 661 user.Email = fields.get(self.info["usermail"], [None])[0] 662 user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 663 user.OverCharge = float(fields.get("pykotaOverCharge", [1.0])[0]) 662 664 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"]) 663 665 if not result : … … 695 697 group.ident = result[0][0] 696 698 group.Name = fields.get("pykotaGroupName", [groupname])[0] 697 group.LimitBy = fields.get("pykotaLimitBy") 698 if group.LimitBy is not None : 699 group.LimitBy = group.LimitBy[0] 700 else : 701 group.LimitBy = "quota" 699 group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 702 700 group.AccountBalance = 0.0 703 701 group.LifeTimePaid = 0.0 … … 717 715 printer.ident = result[0][0] 718 716 printer.Name = fields.get("pykotaPrinterName", [printername])[0] 719 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0] or 0.0)720 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0)717 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 718 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) 721 719 printer.uniqueMember = fields.get("uniqueMember", []) 722 720 printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) … … 732 730 else : 733 731 base = self.info["userquotabase"] 734 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit" ], base=base)732 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 735 733 if result : 736 734 fields = result[0][1] 737 735 userpquota.ident = result[0][0] 738 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0) 739 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0) 736 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 737 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0]) 738 userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0]) 740 739 userpquota.SoftLimit = fields.get("pykotaSoftLimit") 741 740 if userpquota.SoftLimit is not None : … … 815 814 result = None 816 815 try : 817 result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", " createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE)816 result = self.doSearch("objectClass=pykotaJob", ["pykotaJobSizeBytes", "pykotaHostName", "pykotaUserName", "pykotaJobId", "pykotaPrinterPageCounter", "pykotaJobSize", "pykotaAction", "pykotaJobPrice", "pykotaFileName", "pykotaTitle", "pykotaCopies", "pykotaOptions", "pykotaBillingCode", "pykotaPages", "pykotaMD5Sum", "createTimestamp"], base="cn=%s,%s" % (lastjobident, self.info["jobbase"]), scope=ldap.SCOPE_BASE) 818 817 except PyKotaStorageError : 819 818 pass # Last job entry exists, but job probably doesn't exist anymore. … … 823 822 lastjob.JobId = fields.get("pykotaJobId")[0] 824 823 lastjob.UserName = fields.get("pykotaUserName")[0] 825 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0] or 0)824 lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 826 825 try : 827 826 lastjob.JobSize = int(fields.get("pykotaJobSize", [0])[0]) … … 839 838 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 840 839 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 840 lastjob.JobBillingCode = fields.get("pykotaMD5Sum", [None])[0] 841 lastjob.JobMD5Sum = fields.get("pykotaMD5Sum", [None])[0] 842 lastjob.JobPages = fields.get("pykotaPages", [""])[0] 841 843 date = fields.get("createTimestamp", ["19700101000000"])[0] 842 844 year = int(date[:4]) … … 924 926 else : 925 927 base = self.info["userquotabase"] 926 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit" ], base=base)928 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 927 929 if result : 928 930 for (userquotaid, fields) in result : … … 930 932 userpquota = StorageUserPQuota(self, user, printer) 931 933 userpquota.ident = userquotaid 932 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0] or 0) 933 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0] or 0) 934 userpquota.PageCounter = int(fields.get("pykotaPageCounter", [0])[0]) 935 userpquota.LifePageCounter = int(fields.get("pykotaLifePageCounter", [0])[0]) 936 userpquota.WarnCount = int(fields.get("pykotaWarnCount", [0])[0]) 934 937 userpquota.SoftLimit = fields.get("pykotaSoftLimit") 935 938 if userpquota.SoftLimit is not None : … … 990 993 "pykotaUserName" : user.Name, 991 994 "pykotaLimitBy" : (user.LimitBy or "quota"), 995 "pykotaOverCharge" : str(user.OverCharge), 992 996 } 993 997 … … 1048 1052 newfields = { 1049 1053 "pykotaGroupName" : group.Name, 1050 "pykotaLimitB Y" : (group.LimitBy or "quota"),1054 "pykotaLimitBy" : (group.LimitBy or "quota"), 1051 1055 } 1052 1056 mustadd = 1 … … 1102 1106 "pykotaPageCounter" : "0", 1103 1107 "pykotaLifePageCounter" : "0", 1108 "pykotaWarnCount" : "0", 1104 1109 } 1105 1110 if self.info["userquotabase"].lower() == "user" : … … 1141 1146 self.doModify(printer.ident, fields) 1142 1147 1148 def writeUserOverCharge(self, user, factor) : 1149 """Sets the user's overcharging coefficient.""" 1150 fields = { 1151 "pykotaOverCharge" : str(factor), 1152 } 1153 self.doModify(user.ident, fields) 1154 1143 1155 def writeUserLimitBy(self, user, limitby) : 1144 1156 """Sets the user's limiting factor.""" … … 1183 1195 "pykotaLifePageCounter" : str(newlifepagecounter), 1184 1196 "pykotaDateLimit" : None, 1197 "pykotaWarnCount" : "0", 1185 1198 } 1186 1199 return self.doModify(userpquota.ident, fields) … … 1246 1259 "pykotaHostName" : str(clienthost), 1247 1260 "pykotaJobSizeBytes" : str(jobsizebytes), 1261 # TODO : add the 3 missing fields 1248 1262 } 1249 1263 if (not self.disablehistory) or (not printer.LastJob.Exists) : … … 1278 1292 "pykotaHardLimit" : str(hardlimit), 1279 1293 "pykotaDateLimit" : "None", 1294 "pykotaWarnCount" : "0", 1280 1295 } 1281 1296 self.doModify(userpquota.ident, fields) 1297 1298 def writeUserPQuotaWarnCount(self, userpquota, warncount) : 1299 """Sets the warn counter value for a user quota.""" 1300 fields = { 1301 "pykotaWarnCount" : str(warncount or 0), 1302 } 1303 self.doModify(userpquota.ident, fields) 1304 1305 def increaseUserPQuotaWarnCount(self, userpquota) : 1306 """Increases the warn counter value for a user quota.""" 1307 fields = { 1308 "pykotaWarnCount" : { "operator" : "+", "value" : 1, "convert" : int }, 1309 } 1310 return self.doModify(userpquota.ident, fields) 1282 1311 1283 1312 def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) : -
pykota/trunk/pykota/storages/sql.py
r2030 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.65 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.64 2005/01/18 19:47:50 jalet 25 32 # Big bug fix wrt the datelimit attribute … … 273 280 user.LifeTimePaid = fields.get("lifetimepaid") 274 281 user.Email = fields.get("email") 282 user.OverCharge = fields.get("overcharge", 1.0) 275 283 user.Exists = 1 276 284 return user … … 317 325 userpquota.HardLimit = fields.get("hardlimit") 318 326 userpquota.DateLimit = fields.get("datelimit") 327 userpquota.WarnCount = fields.get("warncount") 319 328 userpquota.Exists = 1 320 329 return userpquota … … 359 368 lastjob.JobHostName = fields.get("hostname") 360 369 lastjob.JobSizeBytes = fields.get("jobsizebytes") 370 lastjob.JobMD5Sum = fields.get("md5sum") 371 lastjob.JobPages = fields.get("pages") 372 lastjob.JobBillingCode = fields.get("billingcode") 361 373 lastjob.Exists = 1 362 374 return lastjob … … 374 386 user.LifeTimePaid = record.get("lifetimepaid") 375 387 user.Email = record.get("email") 388 user.OverCharge = record.get("overcharge") 376 389 user.Exists = 1 377 390 groupmembers.append(user) … … 423 436 """Returns the list of users who uses a given printer, along with their quotas.""" 424 437 usersandquotas = [] 425 result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email, userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident))438 result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,overcharge,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit,warncount FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident)) 426 439 if result : 427 440 for record in result : … … 433 446 user.LifeTimePaid = record.get("lifetimepaid") 434 447 user.Email = record.get("email") 448 user.OverCharge = record.get("overcharge") 435 449 user.Exists = 1 436 450 userpquota = StorageUserPQuota(self, user, printer) … … 441 455 userpquota.HardLimit = record.get("hardlimit") 442 456 userpquota.DateLimit = record.get("datelimit") 457 userpquota.WarnCount = record.get("warncount") 443 458 userpquota.Exists = 1 444 459 usersandquotas.append((user, userpquota)) … … 466 481 def addUser(self, user) : 467 482 """Adds a user to the quota storage, returns its id.""" 468 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email ) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email)))483 self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email, overcharge) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy or 'quota'), self.doQuote(user.AccountBalance or 0.0), self.doQuote(user.LifeTimePaid or 0.0), self.doQuote(user.Email), self.doQuote(user.OverCharge))) 469 484 return self.getUser(user.Name) 470 485 … … 503 518 self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 504 519 520 def writeUserOverCharge(self, user, factor) : 521 """Sets the user's overcharging coefficient.""" 522 self.doModify("UPDATE users SET overcharge=%s WHERE id=%s" % (self.doQuote(factor), self.doQuote(user.ident))) 523 505 524 def writeUserLimitBy(self, user, limitby) : 506 525 """Sets the user's limiting factor.""" … … 521 540 def increaseUserPQuotaPagesCounters(self, userpquota, nbpages) : 522 541 """Increase page counters for a user print quota.""" 523 self.doModify("UPDATE userpquota SET pagecounter=pagecounter +%s,lifepagecounter=lifepagecounter+%s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident)))542 self.doModify("UPDATE userpquota SET pagecounter=pagecounter + %s,lifepagecounter=lifepagecounter + %s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident))) 524 543 525 544 def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) : 526 545 """Sets the new page counters permanently for a user print quota.""" 527 self.doModify("UPDATE userpquota SET pagecounter=%s, lifepagecounter=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident)))546 self.doModify("UPDATE userpquota SET pagecounter=%s, lifepagecounter=%s, warncount=0, datelimit=NULL WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident))) 528 547 529 548 def decreaseUserAccountBalance(self, user, amount) : 530 549 """Decreases user's account balance from an amount.""" 531 self.doModify("UPDATE users SET balance=balance -%s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident)))550 self.doModify("UPDATE users SET balance=balance - %s WHERE id=%s" % (self.doQuote(amount), self.doQuote(user.ident))) 532 551 533 552 def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) : … … 565 584 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 566 585 """Sets soft and hard limits for a user quota.""" 567 self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident))) 586 self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, warncount=0, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident))) 587 588 def writeUserPQuotaWarnCount(self, userpquota, warncount) : 589 """Sets the warn counter value for a user quota.""" 590 self.doModify("UPDATE userpquota SET warncount=%s WHERE id=%s" % (self.doQuote(warncount), self.doQuote(userpquota.ident))) 591 592 def increaseUserPQuotaWarnCount(self, userpquota) : 593 """Increases the warn counter value for a user quota.""" 594 self.doModify("UPDATE userpquota SET warncount=warncount+1 WHERE id=%s" % self.doQuote(userpquota.ident)) 568 595 569 596 def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) : … … 620 647 job.JobHostName = fields.get("hostname") 621 648 job.JobSizeBytes = fields.get("jobsizebytes") 649 job.JobMD5Sum = fields.get("md5sum") 650 job.JobPages = fields.get("pages") 651 job.JobBillingCode = fields.get("billingcode") 622 652 job.UserName = fields.get("username") 623 653 job.PrinterName = fields.get("printername") -
pykota/trunk/pykota/tool.py
r2008 r2054 22 22 # 23 23 # $Log$ 24 # Revision 1.149 2005/02/13 22:02:29 jalet 25 # Big database structure changes. Upgrade script is now included as well as 26 # the new LDAP schema. 27 # Introduction of the -o | --overcharge command line option to edpykota. 28 # The output of repykota is more complete, but doesn't fit in 80 columns anymore. 29 # Introduction of the new 'maxdenybanners' directive. 30 # 24 31 # Revision 1.148 2005/01/06 23:24:21 jalet 25 32 # Regain priviledge the time to open the job's data file when printing in … … 1012 1019 return action 1013 1020 else : 1014 val = float(user.AccountBalance or 0.0) 1015 enforcement = self.config.getPrinterEnforcement(printer.Name) 1016 if enforcement == "STRICT" : 1017 val -= self.softwareJobPrice # use precomputed size. 1018 if val <= 0.0 : 1019 action = "DENY" 1020 elif val <= self.config.getPoorMan() : 1021 action = "WARN" 1021 if user.OverCharge == 0.0 : 1022 self.printInfo(_("User %s will not be charged for printing.") % user.Name) 1023 action = "ALLOW" 1022 1024 else : 1023 action = "ALLOW" 1024 if (enforcement == "STRICT") and (val == 0.0) : 1025 action = "WARN" # we can still print until account is 0 1025 val = float(user.AccountBalance or 0.0) 1026 enforcement = self.config.getPrinterEnforcement(printer.Name) 1027 if enforcement == "STRICT" : 1028 val -= self.softwareJobPrice # use precomputed size. 1029 if val <= 0.0 : 1030 action = "DENY" 1031 elif val <= self.config.getPoorMan() : 1032 action = "WARN" 1033 else : 1034 action = "ALLOW" 1035 if (enforcement == "STRICT") and (val == 0.0) : 1036 action = "WARN" # we can still print until account is 0 1026 1037 return action 1027 1038 else : … … 1106 1117 if action.startswith("POLICY_") : 1107 1118 action = action[7:] 1119 1108 1120 if action == "DENY" : 1109 1121 adminmessage = _("Print Quota exceeded for user %s on printer %s") % (user.Name, printer.Name) … … 1286 1298 def exportUserInfo(self, userpquota) : 1287 1299 """Exports user information to the environment.""" 1300 os.environ["PYKOTAOVERCHARGE"] = str(userpquota.User.OverCharge) 1288 1301 os.environ["PYKOTALIMITBY"] = str(userpquota.User.LimitBy) 1289 1302 os.environ["PYKOTABALANCE"] = str(userpquota.User.AccountBalance or 0.0) … … 1294 1307 os.environ["PYKOTAHARDLIMIT"] = str(userpquota.HardLimit) 1295 1308 os.environ["PYKOTADATELIMIT"] = str(userpquota.DateLimit) 1309 os.environ["PYKOTAWARNCOUNT"] = str(userpquota.WarnCount) 1296 1310 1297 1311 # not really an user information, but anyway -
pykota/trunk/pykota/version.py
r2044 r2054 22 22 # 23 23 24 __version__ = "1.21alpha2 3_unofficial"24 __version__ = "1.21alpha24_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""