Show
Ignore:
Timestamp:
03/04/06 15:51:12 (18 years ago)
Author:
jerome
Message:

Code cleaning.
Topped to 10000 the number of times the percent will be displayed by not displaying it if there's no change.
This is very useful when adding 25000 users on 300 printers through an ssh connection...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r2765 r2782  
    7878    return msg 
    7979 
     80class Percent : 
     81    """A class to display progress.""" 
     82    def __init__(self, app, title, size) : 
     83        """Initializes the engine.""" 
     84        self.app = app 
     85        self.size = size 
     86        self.number = 0 
     87        self.factor = 100.0 / float(size) 
     88        self.previous = None 
     89        self.display(title) 
     90         
     91    def display(self, msg) :     
     92        """Displays the value.""" 
     93        self.app.display(msg) 
     94         
     95    def oneMore(self) :     
     96        """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 
     102             
     103    def done(self) :          
     104        """Displays the 'done' message.""" 
     105        self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
     106         
    80107class Tool : 
    81108    """Base class for tools with no database access.""" 
     
    201228            sys.stdout.flush() 
    202229             
    203     def done(self) :     
    204         """Displays the 'done' message.""" 
    205         self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
    206          
    207230    def logdebug(self, message) :     
    208231        """Logs something to debug output if debug is enabled."""