Changeset 3434 for pykota/trunk/pykota/tool.py
- Timestamp:
- 10/05/08 22:50:54 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/tool.py
r3432 r3434 42 42 from pykota import config, storage, logger 43 43 from pykota.version import __version__, __author__, __years__, __gplblurb__ 44 45 class Percent :46 """A class to display progress."""47 def __init__(self, app, size=None) :48 """Initializes the engine."""49 self.isatty = sys.stdout.isatty()50 self.app = app51 self.size = None52 if size :53 self.setSize(size)54 self.previous = None55 self.before = time.time()56 57 def setSize(self, size) :58 """Sets the total size."""59 self.number = 060 self.size = size61 if size :62 self.factor = 100.0 / float(size)63 64 def display(self, msg) :65 """Displays the value."""66 if self.isatty :67 self.app.display(msg)68 sys.stdout.flush()69 70 def oneMore(self) :71 """Increments internal counter."""72 if self.size :73 self.number += 174 percent = "%.02f" % (float(self.number) * self.factor)75 if percent != self.previous : # optimize for large number of items76 self.display("\r%s%%" % percent)77 self.previous = percent78 79 def done(self) :80 """Displays the 'done' message."""81 after = time.time()82 if self.size :83 try :84 speed = self.size / ((after - self.before) + 0.00000000001) # adds an epsilon to avoid an user's problem I can't reproduce...85 except ZeroDivisionError :86 speed = 1 # Fake value in case of division by zero, shouldn't happen anyway with the epsilon above...87 self.display("\r100.00%%\r \r%s. %s : %.2f %s.\n" \88 % (_("Done"), _("Average speed"), speed, _("entries per second")))89 else :90 self.display("\r100.00%%\r \r%s.\n" % _("Done"))91 44 92 45 class Tool : … … 342 295 for c in list(invalidchars) : 343 296 if c in name : 344 return 0345 return 1297 return False 298 return True 346 299 347 300 def _checkUserPQuota(self, userpquota) : … … 466 419 467 420 # indicates that a warning needs to be sent 468 warned = 0421 warned = False 469 422 470 423 # first we check any group the user is a member of … … 480 433 return action 481 434 elif action == "WARN" : 482 warned = 1435 warned = True 483 436 484 437 # Then we check the user's account balance … … 515 468 else : 516 469 # Then check the user quota on current printer and all its parents. 517 policyallowed = 0470 policyallowed = False 518 471 for upquota in [ userpquota ] + userpquota.ParentPrintersUserPQuota : 519 472 action = self._checkUserPQuota(upquota) … … 521 474 return action 522 475 elif action == "WARN" : 523 warned = 1476 warned = True 524 477 elif action == "POLICY_ALLOW" : 525 policyallowed = 1478 policyallowed = True 526 479 if warned : 527 480 return "WARN"