- Timestamp:
- 02/21/06 16:43:18 (19 years ago)
- Location:
- pykota/trunk
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/edpykota
r2731 r2735 166 166 self.display("%s...\n" % _("Deletion")) 167 167 nbtotal = len(pqentries) 168 for i in range(nbtotal) :169 (pqkey, pqentry) = pqentries.popitem()168 i = 0 169 for (pqkey, pqentry) in pqentries.items() : 170 170 if pqentry.Exists : 171 171 pqentry.delete() 172 i += 1 172 173 percent = 100.0 * float(i) / float(nbtotal) 173 174 self.display("\r%.02f%%" % percent) … … 197 198 else : 198 199 pqentries[pqkey] = newpqentry 200 i += 1 199 201 percent = 100.0 * float(i) / float(nbtotal) 200 202 self.display("\r%.02f%%" % percent) 201 i += 1202 203 self.display("\r100.00%%\r \r%s\n" % _("Done.")) 203 204 … … 220 221 else : 221 222 self.display("%s...\n" % _("Modification")) 222 raise PyKotaCommandLineError, "Not implemented yet."223 softlimit = hardlimit = None224 223 225 224 used = options["used"] … … 238 237 raise PyKotaCommandLineError, _("Invalid increase value %s.") % increase 239 238 240 if not options["noquota"] : 239 softlimit = hardlimit = None 240 noquota = options["noquota"] 241 if not noquota : 241 242 if options["softlimit"] : 242 243 try : … … 257 258 self.printInfo(_("Hard limit %i is less than soft limit %i, values will be exchanged.") % (hardlimit, softlimit)) 258 259 (softlimit, hardlimit) = (hardlimit, softlimit) 260 if hardlimit is None : 261 hardlimit = softlimit 262 if hardlimit is not None : 263 self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) 264 if softlimit is None : 265 softlimit = hardlimit 266 if softlimit is not None : 267 self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) 259 268 260 sys.stdout.write(_("Managing print quotas... (this may take a lot of time)")) 261 sys.stdout.flush() 262 missingusers = {} 263 missinggroups = {} 264 changed = {} # tracks changes made at the user/group level 265 for printer in printers : 266 if not options["noquota"] : 267 if hardlimit is None : 268 hardlimit = softlimit 269 if hardlimit is not None : 270 self.printInfo(_("Undefined hard limit set to soft limit (%s) on printer %s.") % (str(hardlimit), printer.Name)) 271 if softlimit is None : 272 softlimit = hardlimit 273 if softlimit is not None : 274 self.printInfo(_("Undefined soft limit set to hard limit (%s) on printer %s.") % (str(softlimit), printer.Name)) 269 nbtotal = len(pqentries) 270 i = 0 271 for pqentry in pqentries : 272 ename = getattr(pqentry, suffix).Name 273 pname = pqentry.Printer.Name 274 if pqentry.Exists : 275 if noquota or ((softlimit is not None) and (hardlimit is not None)) : 276 pqentry.setLimits(softlimit, hardlimit) 277 278 if increase : 279 if (pqentry.SoftLimit is None) \ 280 or (pqentry.HardLimit is None) : 281 self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") 282 else : 283 newsoft = pqentry.SoftLimit + increase 284 newhard = pqentry.HardLimit + increase 285 if (newsoft >= 0) and (newhard >= 0) : 286 pqentry.setLimits(newsoft, newhard) 287 else : 288 self.printInfo(_("You can't set negative limits."), "error") 289 290 if options["reset"] : 291 pqentry.reset() 292 293 if options["hardreset"] : 294 pqentry.hardreset() 295 296 if not options["groups"] : 297 if used : 298 pqentry.setUsage(used) 275 299 276 if options["add"] : 277 allentries = [] 278 for name in names : 279 email = "" 280 if not options["groups"] : 281 splitname = name.split('/', 1) # username/email 282 if len(splitname) == 1 : 283 splitname.append("") 284 (name, email) = splitname 285 if email and (email.count('@') != 1) : 286 self.printInfo(_("Invalid email address %s") % email) 287 email = "" 288 entry = getattr(self.storage, "get%s" % suffix)(name) 289 if email and not options["groups"] : 290 entry.Email = email 291 entrypquota = getattr(self.storage, "get%sPQuota" % suffix)(entry, printer) 292 allentries.append((entry, entrypquota)) 293 else : 294 allentries = getattr(self.storage, "getPrinter%ssAndQuotas" % suffix)(printer, names) 295 296 for (entry, entrypquota) in allentries : 297 if not changed.has_key(entry.Name) : 298 changed[entry.Name] = {} 299 if not options["groups"] : 300 changed[entry.Name]["ingroups"] = [] 301 302 if entry.Exists and (not entrypquota.Exists) : 303 # not found 304 if options["add"] : 305 entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer) 306 307 if not entrypquota.Exists : 308 self.printInfo(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name)) 309 else : 310 if options["noquota"] \ 311 or ((softlimit is not None) and (hardlimit is not None)) : 312 entrypquota.setLimits(softlimit, hardlimit) 313 314 if increase : 315 if (entrypquota.SoftLimit is None) \ 316 or (entrypquota.HardLimit is None) : 317 self.printInfo(_("You can't increase limits by %s when no limit is set.") % increase, "error") 318 else : 319 newsoft = entrypquota.SoftLimit + increase 320 newhard = entrypquota.HardLimit + increase 321 if (newsoft >= 0) and (newhard >= 0) : 322 entrypquota.setLimits(newsoft, newhard) 323 else : 324 self.printInfo(_("You can't set negative limits."), "error") 325 326 if options["reset"] : 327 entrypquota.reset() 328 329 if options["hardreset"] : 330 entrypquota.hardreset() 331 332 if not options["groups"] : 333 if used : 334 entrypquota.setUsage(used) 300 pqentry.save() 301 i += 1 302 percent = 100.0 * float(i) / float(nbtotal) 303 self.display("\r%.02f%%" % percent) 335 304 336 305 if not options["list"] : -
pykota/trunk/pykota/storage.py
r2733 r2735 266 266 def setLimits(self, softlimit, hardlimit) : 267 267 """Sets the soft and hard limit for this quota.""" 268 self.parent.writeUserPQuotaLimits(self, softlimit, hardlimit)269 268 self.SoftLimit = softlimit 270 269 self.HardLimit = hardlimit 271 270 self.DateLimit = None 272 271 self.WarnCount = 0 272 self.isDirty = True 273 273 274 274 def setUsage(self, used) : … … 276 276 vused = int(used) 277 277 if used.startswith("+") or used.startswith("-") : 278 self.parent.beginTransaction()279 try :280 self.parent.increaseUserPQuotaPagesCounters(self, vused)281 self.parent.writeUserPQuotaDateLimit(self, None)282 self.parent.writeUserPQuotaWarnCount(self, 0)283 except PyKotaStorageError, msg :284 self.parent.rollbackTransaction()285 raise PyKotaStorageError, msg286 else :287 self.parent.commitTransaction()288 278 self.PageCounter += vused 289 279 self.LifePageCounter += vused 290 280 else : 291 self.parent.writeUserPQuotaPagesCounters(self, vused, vused)292 281 self.PageCounter = self.LifePageCounter = vused 293 282 self.DateLimit = None 294 283 self.WarnCount = 0 284 self.isDirty = 1 295 285 296 286 def incDenyBannerCounter(self) : … … 306 296 def reset(self) : 307 297 """Resets page counter to 0.""" 308 self.parent.writeUserPQuotaPagesCounters(self, 0, int(self.LifePageCounter or 0))309 298 self.PageCounter = 0 310 299 self.DateLimit = None 300 self.isDirty = True 311 301 312 302 def hardreset(self) : 313 303 """Resets actual and life time page counters to 0.""" 314 self.parent.writeUserPQuotaPagesCounters(self, 0, 0)315 304 self.PageCounter = self.LifePageCounter = 0 316 305 self.DateLimit = None 306 self.isDirty = True 317 307 318 308 def computeJobPrice(self, jobsize) : … … 385 375 uq = self.parent.getUserPQuota(user, self.Printer) 386 376 uq.reset() 387 self.parent.writeGroupPQuotaDateLimit(self, None)377 uq.save() 388 378 except PyKotaStorageError, msg : 389 379 self.parent.rollbackTransaction() … … 393 383 self.PageCounter = 0 394 384 self.DateLimit = None 385 self.isDirty = True 395 386 396 387 def hardreset(self) : … … 401 392 uq = self.parent.getUserPQuota(user, self.Printer) 402 393 uq.hardreset() 403 self.parent.writeGroupPQuotaDateLimit(self, None)394 uq.save() 404 395 except PyKotaStorageError, msg : 405 396 self.parent.rollbackTransaction() … … 409 400 self.PageCounter = self.LifePageCounter = 0 410 401 self.DateLimit = None 402 self.isDirty = True 411 403 412 404 def setDateLimit(self, datelimit) : … … 423 415 def setLimits(self, softlimit, hardlimit) : 424 416 """Sets the soft and hard limit for this quota.""" 425 self.parent.writeGroupPQuotaLimits(self, softlimit, hardlimit)426 417 self.SoftLimit = softlimit 427 418 self.HardLimit = hardlimit 428 419 self.DateLimit = None 420 self.isDirty = True 429 421 430 422 def delete(self) : -
pykota/trunk/pykota/storages/ldapstorage.py
r2726 r2735 1114 1114 return self.doModify(userpquota.ident, fields) 1115 1115 1116 def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :1117 """Sets the new page counters permanently for a user print quota."""1118 fields = {1119 "pykotaPageCounter" : str(newpagecounter),1120 "pykotaLifePageCounter" : str(newlifepagecounter),1121 "pykotaDateLimit" : None,1122 "pykotaWarnCount" : "0",1123 }1124 return self.doModify(userpquota.ident, fields)1125 1126 1116 def decreaseUserAccountBalance(self, user, amount) : 1127 1117 """Decreases user's account balance from an amount.""" … … 1208 1198 self.doAdd(lastjdn, fields) 1209 1199 1210 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) :1211 """S ets soft and hard limits for a user quota."""1200 def saveUserPQuota(self, userpquota) : 1201 """Saves an user print quota entry.""" 1212 1202 fields = { 1213 "pykotaSoftLimit" : str(softlimit), 1214 "pykotaHardLimit" : str(hardlimit), 1215 "pykotaDateLimit" : "None", 1216 "pykotaWarnCount" : "0", 1203 "pykotaSoftLimit" : str(userpquota.SoftLimit), 1204 "pykotaHardLimit" : str(userpquota.HardLimit), 1205 "pykotaDateLimit" : str(userpquota.DateLimit), 1206 "pykotaWarnCount" : str(userpquota.WarnCount), 1207 "pykotaPageCounter" : str(userpquota.PageCounter), 1208 "pykotaLifePageCounter" : str(userpquota.LifePageCounter), 1217 1209 } 1218 1210 self.doModify(userpquota.ident, fields) … … 1232 1224 return self.doModify(userpquota.ident, fields) 1233 1225 1234 def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :1235 """S ets soft and hard limits for a group quota on a specific printer."""1226 def saveGroupPQuota(self, grouppquota) : 1227 """Saves a group print quota entry.""" 1236 1228 fields = { 1237 "pykotaSoftLimit" : str( softlimit),1238 "pykotaHardLimit" : str( hardlimit),1239 "pykotaDateLimit" : "None",1229 "pykotaSoftLimit" : str(grouppquota.SoftLimit), 1230 "pykotaHardLimit" : str(grouppquota.HardLimit), 1231 "pykotaDateLimit" : str(grouppquota.DateLimit), 1240 1232 } 1241 1233 self.doModify(grouppquota.ident, fields) -
pykota/trunk/pykota/storages/sql.py
r2734 r2735 672 672 self.doModify("UPDATE userpquota SET pagecounter=pagecounter + %s,lifepagecounter=lifepagecounter + %s WHERE id=%s" % (self.doQuote(nbpages), self.doQuote(nbpages), self.doQuote(userpquota.ident))) 673 673 674 def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :675 """Sets the new page counters permanently for a user print quota."""676 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)))677 678 674 def saveBillingCode(self, code) : 679 675 """Saves the billing code to the database.""" … … 718 714 self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobprice=%s, filename=%s, title=%s, copies=%s, options=%s, hostname=%s, jobsizebytes=%s, md5sum=%s, pages=%s, billingcode=%s, precomputedjobsize=%s, precomputedjobprice=%s, jobdate=now() WHERE id=%s" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(filename), self.doQuote(title), self.doQuote(copies), self.doQuote(options), self.doQuote(clienthost), self.doQuote(jobsizebytes), self.doQuote(jobmd5sum), self.doQuote(jobpages), self.doQuote(jobbilling), self.doQuote(precomputedsize), self.doQuote(precomputedprice), self.doQuote(printer.LastJob.ident))) 719 715 720 def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) : 721 """Sets soft and hard limits for a user quota.""" 722 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))) 716 def saveUserPQuota(self, userpquota) : 717 """Saves an user print quota entry.""" 718 self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, warncount=%s, datelimit=%s, pagecounter=%s, lifepagecounter=%s WHERE id=%s" \ 719 % (self.doQuote(userpquota.SoftLimit), \ 720 self.doQuote(userpquota.HardLimit), \ 721 self.doQuote(userpquota.WarnCount), \ 722 self.doQuote(userpquota.DateLimit), \ 723 self.doQuote(userpquota.PageCounter), \ 724 self.doQuote(userpquota.LifePageCounter), \ 725 self.doQuote(userpquota.ident))) 723 726 724 727 def writeUserPQuotaWarnCount(self, userpquota, warncount) : … … 730 733 self.doModify("UPDATE userpquota SET warncount=warncount+1 WHERE id=%s" % self.doQuote(userpquota.ident)) 731 734 732 def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) : 733 """Sets soft and hard limits for a group quota on a specific printer.""" 734 self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(grouppquota.ident))) 735 def saveGroupPQuota(self, grouppquota) : 736 """Saves a group print quota entry.""" 737 self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=%s WHERE id=%s" \ 738 % (self.doQuote(grouppquota.SoftLimit), \ 739 self.doQuote(grouppquota.HardLimit), \ 740 self.doQuote(grouppquota.DateLimit), \ 741 self.doQuote(grouppquota.ident))) 735 742 736 743 def writePrinterToGroup(self, pgroup, printer) :