Changeset 2783 for pykota/trunk/pykota/tool.py
- Timestamp:
- 03/05/06 09:36:47 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/tool.py
r2782 r2783 35 35 import tempfile 36 36 import md5 37 import time 37 38 import ConfigParser 38 39 import popen2 … … 80 81 class Percent : 81 82 """A class to display progress.""" 82 def __init__(self, app, title, size) :83 def __init__(self, app, size=None) : 83 84 """Initializes the engine.""" 84 85 self.app = app 86 self.size = None 87 if size : 88 self.setSize(size) 89 self.previous = None 90 self.before = time.time() 91 92 def setSize(self, size) : 93 """Sets the total size.""" 94 self.number = 0 85 95 self.size = size 86 self.number = 087 96 self.factor = 100.0 / float(size) 88 self.previous = None89 self.display(title)90 97 91 98 def display(self, msg) : … … 95 102 def oneMore(self) : 96 103 """Increments internal counter.""" 97 self.number += 1 98 percent = "%.02f" % (float(self.number) * self.factor) 99 if percent != self.previous : # optimize for large number of items 100 self.display("\r%s%%" % percent) 101 self.previous = percent 104 if self.size : 105 self.number += 1 106 percent = "%.02f" % (float(self.number) * self.factor) 107 if percent != self.previous : # optimize for large number of items 108 self.display("\r%s%%" % percent) 109 self.previous = percent 102 110 103 111 def done(self) : 104 112 """Displays the 'done' message.""" 105 self.display("\r100.00%%\r \r%s\n" % _("Done.")) 113 after = time.time() 114 if self.size : 115 speed = int(self.size / (after - self.before)) 116 self.display("\r100.00%%\r \r%s. %s : %i %s.\n" \ 117 % (_("Done"), _("Average speed"), speed, _("entries per second"))) 118 else : 119 self.display("\r100.00%%\r \r%s.\n" % _("Done")) 106 120 107 121 class Tool :