Changeset 1365
- Timestamp:
- 02/26/04 15:18:07 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1335 r1365 24 24 # 25 25 # $Log$ 26 # Revision 1.28 2004/02/26 14:18:07 jalet 27 # Should fix the remaining bugs wrt printers groups and users groups. 28 # 26 29 # Revision 1.27 2004/02/04 23:41:27 jalet 27 30 # Should fix the incorrect "backend died abnormally" problem. … … 198 201 # be allowed if current user is allowed to print on this printer 199 202 if policy == "OK" : 200 self.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name))201 203 action = self.warnUserPQuota(userpquota) 202 204 self.logdebug("Job accounting begins.") -
pykota/trunk/NEWS
r1363 r1365 22 22 PyKota NEWS : 23 23 24 - 1.18alpha10 : 25 26 - Fixed nested printer groups accounting. 27 28 - Fixed user groups + printer groups problem. 29 24 30 - 1.18alpha9 : 25 31 -
pykota/trunk/pykota/storage.py
r1364 r1365 22 22 # 23 23 # $Log$ 24 # Revision 1.46 2004/02/26 14:18:07 jalet 25 # Should fix the remaining bugs wrt printers groups and users groups. 26 # 24 27 # Revision 1.45 2004/02/26 10:40:40 jalet 25 28 # Fixed nested printer groups accounting. … … 394 397 self.DateLimit = None 395 398 399 def __getattr__(self, name) : 400 """Delays data retrieval until it's really needed.""" 401 if name == "ParentPrintersGroupPQuota" : 402 self.ParentPrintersGroupPQuota = (self.Group.Exists and self.Printer.Exists and self.parent.getParentPrintersGroupPQuota(self)) or [] 403 return self.ParentPrintersGroupPQuota 404 else : 405 raise AttributeError, name 406 396 407 def setDateLimit(self, datelimit) : 397 408 """Sets the date limit for this quota.""" … … 555 566 for parent in printer.Parents[:] : 556 567 printer.Parents.extend(self.getParentPrinters(parent)) 557 self.tool.logdebug("=== %i ===> %s" % (len(printer.Parents), [p.Name for p in printer.Parents]))558 568 return printer.Parents 559 569 … … 586 596 def getParentPrintersUserPQuota(self, userpquota) : 587 597 """Returns all user print quota on the printer and all its parents recursively.""" 588 upquotas = [ ]598 upquotas = [ ] 589 599 for printer in self.getParentPrinters(userpquota.Printer) : 590 600 upquotas.append(self.getUserPQuota(userpquota.User, printer)) 591 self.tool.logdebug("UPQUOTAS : %i ===> %s" % (len(upquotas), ["%s/%s" % (upq.User.Name, upq.Printer.Name) for upq in upquotas]))592 601 return upquotas 602 603 def getParentPrintersGroupPQuota(self, grouppquota) : 604 """Returns all group print quota on the printer and all its parents recursively.""" 605 gpquotas = [ ] 606 for printer in self.getParentPrinters(grouppquota.Printer) : 607 gpquotas.append(self.getGroupPQuota(grouppquota.Group, printer)) 608 return gpquotas 593 609 594 610 def openConnection(pykotatool) : -
pykota/trunk/pykota/storages/ldapstorage.py
r1361 r1365 22 22 # 23 23 # $Log$ 24 # Revision 1.57 2004/02/26 14:18:07 jalet 25 # Should fix the remaining bugs wrt printers groups and users groups. 26 # 24 27 # Revision 1.56 2004/02/25 16:52:39 jalet 25 28 # Small fix wrt empty user groups … … 383 386 self.tool.logdebug("QUERY : Modify(%s, %s ==> %s)" % (dn, oldentry, fields)) 384 387 entry = ldap.modlist.modifyModlist(oldentry, fields, ignore_oldexistent=ignoreold) 385 self.database.modify_s(dn, entry) 388 modentry = [] 389 for (mop, mtyp, mval) in entry : 390 if mtyp != "createTimestamp" : 391 modentry.append((mop, mtyp, mval)) 392 self.tool.logdebug("MODIFY : %s ==> %s ==> %s" % (fields, entry, modentry)) 393 if modentry : 394 self.database.modify_s(dn, modentry) 386 395 except ldap.LDAPError, msg : 387 396 raise PyKotaStorageError, (_("Problem modifying LDAP entry (%s, %s)") % (dn, fields)) + " : %s" % str(msg) -
pykota/trunk/pykota/tool.py
r1353 r1365 22 22 # 23 23 # $Log$ 24 # Revision 1.74 2004/02/26 14:18:07 jalet 25 # Should fix the remaining bugs wrt printers groups and users groups. 26 # 24 27 # Revision 1.73 2004/02/19 14:20:21 jalet 25 28 # maildomain pykota.conf directive added. … … 448 451 self.sendMessage(adminmail, adminmail, "Subject: %s\n\n%s" % (subject, message)) 449 452 453 def _checkUserPQuota(self, userpquota) : 454 """Checks the user quota on a printer and deny or accept the job.""" 455 # then we check the user's own quota 456 # if we get there we are sure that policy is not EXTERNAL 457 user = userpquota.User 458 printer = userpquota.Printer 459 self.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) 460 (policy, dummy) = self.config.getPrinterPolicy(userpquota.Printer.Name) 461 if not userpquota.Exists : 462 # Unknown userquota 463 if policy == "ALLOW" : 464 action = "POLICY_ALLOW" 465 else : 466 action = "POLICY_DENY" 467 self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action)) 468 else : 469 pagecounter = int(userpquota.PageCounter or 0) 470 if userpquota.SoftLimit is not None : 471 softlimit = int(userpquota.SoftLimit) 472 if pagecounter < softlimit : 473 action = "ALLOW" 474 else : 475 if userpquota.HardLimit is None : 476 # only a soft limit, this is equivalent to having only a hard limit 477 action = "DENY" 478 else : 479 hardlimit = int(userpquota.HardLimit) 480 if softlimit <= pagecounter < hardlimit : 481 now = DateTime.now() 482 if userpquota.DateLimit is not None : 483 datelimit = DateTime.ISO.ParseDateTime(userpquota.DateLimit) 484 else : 485 datelimit = now + self.config.getGraceDelay(printer.Name) 486 userpquota.setDateLimit(datelimit) 487 if now < datelimit : 488 action = "WARN" 489 else : 490 action = "DENY" 491 else : 492 action = "DENY" 493 else : 494 if userpquota.HardLimit is not None : 495 # no soft limit, only a hard one. 496 hardlimit = int(userpquota.HardLimit) 497 if pagecounter < hardlimit : 498 action = "ALLOW" 499 else : 500 action = "DENY" 501 else : 502 # Both are unset, no quota, i.e. accounting only 503 action = "ALLOW" 504 return action 505 450 506 def checkGroupPQuota(self, grouppquota) : 451 507 """Checks the group quota on a printer and deny or accept the job.""" 452 508 group = grouppquota.Group 453 509 printer = grouppquota.Printer 510 self.logdebug("Checking group %s's quota on printer %s" % (group.Name, printer.Name)) 454 511 if group.LimitBy and (group.LimitBy.lower() == "balance") : 455 512 if group.AccountBalance <= 0.0 : … … 497 554 498 555 def checkUserPQuota(self, userpquota) : 499 """Checks the user quota on a printer and deny or accept the job."""556 """Checks the user quota on a printer and all its parents and deny or accept the job.""" 500 557 user = userpquota.User 501 558 printer = userpquota.Printer 559 560 # indicates that a warning needs to be sent 561 warned = 0 502 562 503 563 # first we check any group the user is a member of 504 564 for group in self.storage.getUserGroups(user) : 505 565 grouppquota = self.storage.getGroupPQuota(group, printer) 506 if grouppquota.Exists : 507 action = self.checkGroupPQuota(grouppquota) 508 if action == "DENY" : 509 return action 510 511 # then we check the user's own quota 566 # for the printer and all its parents 567 for gpquota in [ grouppquota ] + grouppquota.ParentPrintersGroupPQuota : 568 if gpquota.Exists : 569 action = self.checkGroupPQuota(gpquota) 570 if action == "DENY" : 571 return action 572 elif action == "WARN" : 573 warned = 1 574 575 # Then we check the user's account balance 512 576 # if we get there we are sure that policy is not EXTERNAL 513 577 (policy, dummy) = self.config.getPrinterPolicy(printer.Name) 514 578 if user.LimitBy and (user.LimitBy.lower() == "balance") : 579 self.logdebug("Checking account balance for user %s" % user.Name) 515 580 if user.AccountBalance is None : 516 581 if policy == "ALLOW" : … … 519 584 action = "POLICY_DENY" 520 585 self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (user.Name, action, printer.Name)) 586 return action 521 587 else : 522 588 val = float(user.AccountBalance or 0.0) 523 589 if val <= 0.0 : 524 action ="DENY"590 return "DENY" 525 591 elif val <= self.config.getPoorMan() : 526 action ="WARN"592 return "WARN" 527 593 else : 528 action ="ALLOW"594 return "ALLOW" 529 595 else : 530 if not userpquota.Exists : 531 # Unknown userquota 532 if policy == "ALLOW" : 533 action = "POLICY_ALLOW" 534 else : 535 action = "POLICY_DENY" 536 self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action)) 596 # Then check the user quota on current printer and all its parents. 597 policyallowed = 0 598 for upquota in [ userpquota ] + userpquota.ParentPrintersUserPQuota : 599 action = self._checkUserPQuota(upquota) 600 if action in ("DENY", "POLICY_DENY") : 601 return action 602 elif action == "WARN" : 603 warned = 1 604 elif action == "POLICY_ALLOW" : 605 policyallowed = 1 606 if warned : 607 return "WARN" 608 elif policyallowed : 609 return "POLICY_ALLOW" 537 610 else : 538 pagecounter = int(userpquota.PageCounter or 0) 539 if userpquota.SoftLimit is not None : 540 softlimit = int(userpquota.SoftLimit) 541 if pagecounter < softlimit : 542 action = "ALLOW" 543 else : 544 if userpquota.HardLimit is None : 545 # only a soft limit, this is equivalent to having only a hard limit 546 action = "DENY" 547 else : 548 hardlimit = int(userpquota.HardLimit) 549 if softlimit <= pagecounter < hardlimit : 550 now = DateTime.now() 551 if userpquota.DateLimit is not None : 552 datelimit = DateTime.ISO.ParseDateTime(userpquota.DateLimit) 553 else : 554 datelimit = now + self.config.getGraceDelay(printer.Name) 555 userpquota.setDateLimit(datelimit) 556 if now < datelimit : 557 action = "WARN" 558 else : 559 action = "DENY" 560 else : 561 action = "DENY" 562 else : 563 if userpquota.HardLimit is not None : 564 # no soft limit, only a hard one. 565 hardlimit = int(userpquota.HardLimit) 566 if pagecounter < hardlimit : 567 action = "ALLOW" 568 else : 569 action = "DENY" 570 else : 571 # Both are unset, no quota, i.e. accounting only 572 action = "ALLOW" 573 return action 574 611 return "ALLOW" 612 575 613 def externalMailTo(self, cmd, action, user, printer, message) : 576 614 """Warns the user with an external command.""" -
pykota/trunk/pykota/version.py
r1360 r1365 22 22 # 23 23 24 __version__ = "1.18alpha 9_unofficial"24 __version__ = "1.18alpha10_unofficial" 25 25 26 26 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""