Changeset 3549
- Timestamp:
- 08/18/10 04:20:57 (14 years ago)
- Location:
- pykota/trunk
- Files:
-
- 1 added
- 13 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r3545 r3549 557 557 setenv("PYKOTALIFETIMEPAID", str(self.User.LifeTimePaid or 0.0), self.charset) 558 558 setenv("PYKOTAUSERDESCRIPTION", self.User.Description or "", self.charset) 559 setenv("PYKOTAMAXJOBSIZE", ((self.UserPQuota.MaxJobSize is None) and _("Unlimited")) or str(self.UserPQuota.MaxJobSize), self.charset) 559 560 560 561 setenv("PYKOTAPAGECOUNTER", str(self.UserPQuota.PageCounter or 0), self.charset) … … 1027 1028 # This printer was set to refuse jobs this large. 1028 1029 self.printInfo(_("Precomputed job size (%s pages) too large for printer %s.") % (self.softwareJobSize, self.PrinterName), "warn") 1030 self.Action = "DENY" 1031 # here we don't put the precomputed job size in the message 1032 # because in case of error the user could complain :-) 1033 self.Reason = _("You are not allowed to print so many pages on printer %s at this time.") % self.PrinterName 1034 1035 if self.Action not in ("DENY", "CANCEL") : 1036 if (self.UserPQuota.MaxJobSize is not None) and (self.softwareJobSize > self.UserPQuota.MaxJobSize) : 1037 # This user print quota entry was set to refuse jobs this large. 1038 self.printInfo(_("Precomputed job size (%s pages) too large for user %s on printer %s.") % (self.softwareJobSize, self.UserName, self.PrinterName), "warn") 1029 1039 self.Action = "DENY" 1030 1040 # here we don't put the precomputed job size in the message -
pykota/trunk/bin/edpykota
r3489 r3549 36 36 class EdPyKota(PyKotaTool) : 37 37 """A class for edpykota.""" 38 def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used ) :38 def modifyPQEntry(self, pqkey, pqentry, noquota, softlimit, hardlimit, increase, reset, hardreset, suffix, used, maxjobsize) : 39 39 """Modifies a print quota entry.""" 40 40 if noquota or ((softlimit is not None) and (hardlimit is not None)) : … … 54 54 if used : 55 55 pqentry.setUsage(used) 56 if maxjobsize is not None : 57 if maxjobsize == "unlimited" : 58 pqentry.setMaxJobSize(None) 59 else : 60 pqentry.setMaxJobSize(maxjobsize) 56 61 57 62 def main(self, names, options) : … … 77 82 or options.noquota \ 78 83 or options.increase \ 84 or options.maxjobsize \ 79 85 or options.skipexisting))) \ 80 86 or (options.groups and (options.used \ 87 or options.maxjobsize \ 81 88 or options.increase \ 82 89 or options.reset \ … … 106 113 self.display(" %s\n" % (_("Hard limit : %s") % pqentry.HardLimit)) 107 114 self.display(" %s\n" % (_("Date limit : %s") % pqentry.DateLimit)) 108 self.display(" %s (Not supported yet)\n" % (_("Maximum job size : %s") % ((pqentry.MaxJobSize and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited")))) 115 if suffix == "User" : 116 self.display(" %s\n" % (_("Maximum job size : %s") % (((pqentry.MaxJobSize is not None) and (_("%s pages") % pqentry.MaxJobSize)) or _("Unlimited")))) 109 117 if hasattr(pqentry, "WarnCount") : 110 118 self.display(" %s\n" % (_("Warning banners printed : %s") % pqentry.WarnCount)) … … 159 167 self.printInfo(_("Undefined soft limit set to hard limit (%s).") % str(softlimit)) 160 168 169 if options.maxjobsize : 170 if options.maxjobsize.lower() == "unlimited" : 171 maxjobsize = "unlimited" 172 else : 173 try : 174 maxjobsize = int(options.maxjobsize) 175 if maxjobsize < 0 : 176 raise ValueError 177 except ValueError : 178 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 179 else : 180 maxjobsize = None 181 161 182 self.storage.beginTransaction() 162 183 try : … … 183 204 options.hardreset, 184 205 suffix, 185 used) 206 used, 207 maxjobsize) 186 208 oldpqentry = getattr(self.storage, "add%sPQuota" % suffix)(pqentry) 187 209 if oldpqentry is not None : … … 201 223 options.hardreset, 202 224 suffix, 203 used) 225 used, 226 maxjobsize) 204 227 oldpqentry.save() 205 228 percent.oneMore() … … 220 243 options.hardreset, 221 244 suffix, 222 used) 245 used, 246 maxjobsize) 223 247 pqentry.save() 224 248 percent.oneMore() … … 263 287 dest="action", 264 288 help=_("Display detailed informations about the specified users or groups print quota entries.")) 289 parser.add_option("-m", "--maxjobsize", 290 dest="maxjobsize", 291 help=_("Set the maximum job size in pages the specified users are allowed to print to the specified printers in a single job. Accepted values are '0' to forbid printing, 'unlimited' to allow unrestricted printing, or any positive integer value. This option is not supported for users groups.")) 265 292 parser.add_option("-n", "--noquota", 266 293 dest="noquota", -
pykota/trunk/bin/pkprinters
r3489 r3549 50 50 printer.setPassThrough(True) 51 51 if maxjobsize is not None : 52 printer.setMaxJobSize(maxjobsize) 52 if maxjobsize == "unlimited" : 53 printer.setMaxJobSize(None) 54 else : 55 printer.setMaxJobSize(maxjobsize) 53 56 54 57 def managePrintersGroups(self, pgroups, printer, remove) : … … 151 154 (_("Passthrough mode : %s") % ((printer.PassThrough and _("ON")) or _("OFF")))) 152 155 self.display(" %s\n" % \ 153 (_("Maximum job size : %s") % (( printer.MaxJobSizeand (_("%s pages") % printer.MaxJobSize)) or _("Unlimited"))))156 (_("Maximum job size : %s") % (((printer.MaxJobSize is not None) and (_("%s pages") % printer.MaxJobSize)) or _("Unlimited")))) 154 157 self.display(" %s\n" % (_("Routed through PyKota : %s") % ((self.isPrinterCaptured(printer.Name) and _("YES")) or _("NO")))) 155 158 if parents : … … 188 191 189 192 if options.maxjobsize : 190 try : 191 maxjobsize = int(options.maxjobsize) 192 if maxjobsize < 0 : 193 raise ValueError 194 except ValueError : 195 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 193 if options.maxjobsize.lower() == "unlimited" : 194 maxjobsize = "unlimited" 195 else : 196 try : 197 maxjobsize = int(options.maxjobsize) 198 if maxjobsize < 0 : 199 raise ValueError 200 except ValueError : 201 raise PyKotaCommandLineError, _("Invalid maximum job size value %s") % options.maxjobsize 196 202 else : 197 203 maxjobsize = None … … 306 312 parser.add_option("-m", "--maxjobsize", 307 313 dest="maxjobsize", 308 help=_("Set the maximum job size in pages allowed on the specified printers. "))314 help=_("Set the maximum job size in pages allowed on the specified printers. Accepted values are '0' to forbid printing, 'unlimited' to allow unrestricted printing, or any positive integer value.")) 309 315 parser.add_option("-n", "--nopassthrough", 310 316 action="store_true", -
pykota/trunk/bin/pykotme
r3489 r3549 92 92 userpquota = self.storage.getUserPQuota(user, printer) 93 93 if userpquota.Exists : 94 if printer.MaxJobSize and (totalsize > printer.MaxJobSize) : 94 if (printer.MaxJobSize and (totalsize > printer.MaxJobSize)) \ 95 or (userpquota.MaxJobSize and (totalsize > userpquota.MaxJobSize)) : 95 96 self.display("%s\n" % (_("User %(username)s is not allowed to print so many pages on printer %(printername)s at this time.") % locals())) 96 97 else : -
pykota/trunk/cgi-bin/pykotme.cgi
r3489 r3549 182 182 upquota = self.storage.getUserPQuota(user, printer) 183 183 if upquota.Exists : 184 if printer.MaxJobSize and (jobsize > printer.MaxJobSize) : 184 if (printer.MaxJobSize and (jobsize > printer.MaxJobSize)) \ 185 or (upquota.MaxJobSize and (jobsize > upquota.MaxJobSize)) : 185 186 msg = _("You are not allowed to print so many pages on printer %s at this time.") % printer.Name 186 187 else : -
pykota/trunk/initscripts/ldap/pykota.schema
r3481 r3549 5 5 # LDAP Schema for Pykota Quota System 6 6 # 7 # (c) 2003-20 09Jerome Alet <alet@librelogiciel.com>7 # (c) 2003-2010 Jerome Alet <alet@librelogiciel.com> 8 8 # This program is free software: you can redistribute it and/or modify 9 9 # it under the terms of the GNU General Public License as published by … … 293 293 294 294 # pykotaGroupPQuota 295 # NB : we still allow pykotaMaxJobSize here but 296 # only to not break existing LDAP directories. 297 # This attribute is not supported for users groups. 295 298 objectclass ( 1.3.6.1.4.1.16868.1.2.5 NAME 'pykotaGroupPQuota' SUP top AUXILIARY 296 299 DESC 'PyKota Group Quota on a Printer' -
pykota/trunk/initscripts/mysql/pykota-mysql.sql
r3481 r3549 141 141 softlimit INT4, 142 142 hardlimit INT4, 143 maxjobsize INT4,144 143 datelimit DATETIME, 145 144 INDEX (groupid), -
pykota/trunk/initscripts/postgresql/pykota-postgresql.sql
r3481 r3549 129 129 softlimit INT4, 130 130 hardlimit INT4, 131 maxjobsize INT4,132 131 datelimit TIMESTAMP); 133 132 CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); -
pykota/trunk/initscripts/sqlite/pykota-sqlite.sql
r3481 r3549 112 112 softlimit INT4, 113 113 hardlimit INT4, 114 maxjobsize INT4,115 114 datelimit TEXT); 116 115 CREATE INDEX grouppquota_g_id_ix ON grouppquota (groupid); -
pykota/trunk/pykota/storage.py
r3526 r3549 354 354 return jobprice 355 355 356 def setMaxJobSize(self, maxjobsize) : 357 """Sets the maximal job size for this print quota entry.""" 358 self.MaxJobSize = maxjobsize 359 self.isDirty = True 360 356 361 def delete(self) : 357 362 """Deletes an user print quota entry from the database.""" … … 380 385 self.HardLimit = None 381 386 self.DateLimit = None 382 self.MaxJobSize = None383 387 384 388 def __getattr__(self, name) : -
pykota/trunk/pykota/storages/ldapstorage.py
r3532 r3549 447 447 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 448 448 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) 449 printer.MaxJobSize = int(fields.get("pykotaMaxJobSize", [0])[0]) 449 printer.MaxJobSize = fields.get("pykotaMaxJobSize") 450 if printer.MaxJobSize is not None : 451 if printer.MaxJobSize[0].upper() == "NONE" : 452 printer.MaxJobSize = None 453 else : 454 printer.MaxJobSize = int(printer.MaxJobSize[0]) 450 455 printer.PassThrough = fields.get("pykotaPassThrough", [None])[0] 451 456 if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : … … 513 518 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 514 519 (unicodeToDatabase(group.Name), unicodeToDatabase(printer.Name)), \ 515 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit" , "pykotaMaxJobSize"], \520 ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], \ 516 521 base=base) 517 522 if result : … … 536 541 else : 537 542 grouppquota.DateLimit = grouppquota.DateLimit[0] 538 grouppquota.MaxJobSize = fields.get("pykotaMaxJobSize")539 if grouppquota.MaxJobSize is not None :540 if grouppquota.MaxJobSize[0].upper() == "NONE" :541 grouppquota.MaxJobSize = None542 else :543 grouppquota.MaxJobSize = int(grouppquota.MaxJobSize[0])544 543 grouppquota.PageCounter = 0 545 544 grouppquota.LifePageCounter = 0 … … 712 711 printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0] or 0.0) 713 712 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 714 printer.MaxJobSize = int(fields.get("pykotaMaxJobSize", [0])[0]) 713 printer.MaxJobSize = fields.get("pykotaMaxJobSize") 714 if printer.MaxJobSize is not None : 715 if printer.MaxJobSize[0].upper() == "NONE" : 716 printer.MaxJobSize = None 717 else : 718 printer.MaxJobSize = int(printer.MaxJobSize[0]) 715 719 printer.PassThrough = fields.get("pykotaPassThrough", [None])[0] 716 720 if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : … … 892 896 "pykotaPrinterName" : printername, 893 897 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 894 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0),898 "pykotaMaxJobSize" : str(printer.MaxJobSize), 895 899 "description" : unicodeToDatabase(printer.Description or ""), 896 900 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), … … 1070 1074 "pykotaLifePageCounter" : str(upq.LifePageCounter or 0), 1071 1075 "pykotaWarnCount" : str(upq.WarnCount or 0), 1072 "pykotaMaxJobSize" : str(upq.MaxJobSize or 0),1076 "pykotaMaxJobSize" : str(upq.MaxJobSize), 1073 1077 } 1074 1078 if self.info["userquotabase"].lower() == "user" : … … 1106 1110 fields = { 1107 1111 "pykotaPassThrough" : (printer.PassThrough and "t") or "f", 1108 "pykotaMaxJobSize" : str(printer.MaxJobSize or 0),1112 "pykotaMaxJobSize" : str(printer.MaxJobSize), 1109 1113 "description" : unicodeToDatabase(printer.Description or ""), 1110 1114 "pykotaPricePerPage" : str(printer.PricePerPage or 0.0), … … 1251 1255 "pykotaPageCounter" : str(userpquota.PageCounter or 0), 1252 1256 "pykotaLifePageCounter" : str(userpquota.LifePageCounter or 0), 1253 "pykotaMaxJobSize" : str(userpquota.MaxJobSize or 0),1257 "pykotaMaxJobSize" : str(userpquota.MaxJobSize), 1254 1258 } 1255 1259 self.doModify(userpquota.ident, fields) … … 1275 1279 "pykotaHardLimit" : str(grouppquota.HardLimit), 1276 1280 "pykotaDateLimit" : str(grouppquota.DateLimit), 1277 "pykotaMaxJobSize" : str(grouppquota.MaxJobSize or 0),1278 1281 } 1279 1282 self.doModify(grouppquota.ident, fields) … … 1680 1683 entries = [p for p in [self.getPrinter(name) for name in self.getAllPrintersNames(pname)] if p.Exists] 1681 1684 if entries : 1682 fields = ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit" )1685 fields = ("username", "printername", "dn", "userdn", "printerdn", "lifepagecounter", "pagecounter", "softlimit", "hardlimit", "datelimit", "maxjobsize") 1683 1686 result = [] 1684 1687 uname = extractonly.get("username") 1685 1688 for entry in entries : 1686 1689 for (user, userpquota) in self.getPrinterUsersAndQuotas(entry, names=[uname or "*"]) : 1687 result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit ))1690 result.append((user.Name, entry.Name, userpquota.ident, user.ident, entry.ident, userpquota.LifePageCounter, userpquota.PageCounter, userpquota.SoftLimit, userpquota.HardLimit, userpquota.DateLimit, userpquota.MaxJobSize)) 1688 1691 return [fields] + self.sortRecords(fields, result, ["+userdn"], ordering) 1689 1692 -
pykota/trunk/pykota/storages/sql.py
r3541 r3549 62 62 printer.PricePerJob = record.get("priceperjob") or 0.0 63 63 printer.PricePerPage = record.get("priceperpage") or 0.0 64 printer.MaxJobSize = record.get("maxjobsize") or 064 printer.MaxJobSize = record.get("maxjobsize") 65 65 printer.PassThrough = record.get("passthrough") or 0 66 66 if printer.PassThrough in (1, "1", "t", "true", "TRUE", "True") : … … 119 119 userpquota.HardLimit = record.get("hardlimit") 120 120 userpquota.DateLimit = record.get("datelimit") 121 userpquota.MaxJobSize = record.get("maxjobsize") 121 122 userpquota.WarnCount = record.get("warncount") or 0 122 123 userpquota.Exists = True … … 243 244 thefilter = "AND %s" % thefilter 244 245 orderby = self.createOrderBy(["+grouppquota.id"], ordering) 245 result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) %(thefilter)s GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,group pquota.maxjobsize,groups.groupname,printers.printername ORDER BY %(orderby)s" % locals())246 result = self.doRawSearch("SELECT groups.groupname,printers.printername,grouppquota.*,coalesce(sum(pagecounter), 0) AS pagecounter,coalesce(sum(lifepagecounter), 0) AS lifepagecounter FROM groups,printers,grouppquota,userpquota WHERE groups.id=grouppquota.groupid AND printers.id=grouppquota.printerid AND userpquota.printerid=grouppquota.printerid AND userpquota.userid IN (SELECT userid FROM groupsmembers WHERE groupsmembers.groupid=grouppquota.groupid) %(thefilter)s GROUP BY grouppquota.id,grouppquota.groupid,grouppquota.printerid,grouppquota.softlimit,grouppquota.hardlimit,grouppquota.datelimit,groups.groupname,printers.printername ORDER BY %(orderby)s" % locals()) 246 247 return self.prepareRawResult(result) 247 248 … … 560 561 % (self.doQuote(unicodeToDatabase(printer.Name)), \ 561 562 self.doQuote((printer.PassThrough and "t") or "f"), \ 562 self.doQuote(printer.MaxJobSize or 0), \563 self.doQuote(printer.MaxJobSize), \ 563 564 self.doQuote(unicodeToDatabase(printer.Description)), \ 564 565 self.doQuote(printer.PricePerPage or 0.0), \ … … 650 651 if oldentry.Exists : 651 652 return oldentry 652 self.doModify("INSERT INTO grouppquota (groupid, printerid, softlimit, hardlimit, datelimit , maxjobsize) VALUES (%s,%s, %s, %s, %s, %s)" \653 self.doModify("INSERT INTO grouppquota (groupid, printerid, softlimit, hardlimit, datelimit) VALUES (%s, %s, %s, %s, %s)" \ 653 654 % (self.doQuote(gpq.Group.ident), \ 654 655 self.doQuote(gpq.Printer.ident), \ 655 656 self.doQuote(gpq.SoftLimit), \ 656 657 self.doQuote(gpq.HardLimit), \ 657 self.doQuote(gpq.DateLimit), \ 658 self.doQuote(gpq.MaxJobSize))) 658 self.doQuote(gpq.DateLimit))) 659 659 gpq.isDirty = False 660 660 return None # the entry created doesn't need further modification … … 664 664 self.doModify("UPDATE printers SET passthrough=%s, maxjobsize=%s, description=%s, priceperpage=%s, priceperjob=%s WHERE id=%s" \ 665 665 % (self.doQuote((printer.PassThrough and "t") or "f"), \ 666 self.doQuote(printer.MaxJobSize or 0), \666 self.doQuote(printer.MaxJobSize), \ 667 667 self.doQuote(unicodeToDatabase(printer.Description)), \ 668 668 self.doQuote(printer.PricePerPage or 0.0), \ -
pykota/trunk/pykota/version.py
r3547 r3549 24 24 import time 25 25 26 __version__ = "1.27alpha1 2_unofficial"26 __version__ = "1.27alpha13_unofficial" 27 27 28 28 __doc__ = "PyKota : a complete Printing Quota Solution for CUPS."