source: main/waeup.sirp/branches/ulif-stress-multimech/multi-mechanize/lib/progressbar.py @ 7486

Last change on this file since 7486 was 7478, checked in by uli, 13 years ago

Sample usage of multi-mechanize (not finished).

File size: 1.2 KB
RevLine 
[7478]1#!/usr/bin/env python
2#
3#  Copyright (c) 2010 Corey Goldberg (corey@goldb.org)
4#  License: GNU LGPLv3
5
6#  This file is part of Multi-Mechanize
7
8
9
10class ProgressBar(object):
11    def __init__(self, duration):
12        self.duration = duration
13        self.prog_bar = '[]'
14        self.fill_char = '='
15        self.width = 40
16        self.__update_amount(0)
17   
18    def __update_amount(self, new_amount):
19        percent_done = int(round((new_amount / 100.0) * 100.0))
20        if percent_done > 100:
21            percent_done = 100
22        all_full = self.width - 2
23        num_hashes = int(round((percent_done / 100.0) * all_full))
24        self.prog_bar = '[' + self.fill_char * num_hashes + ' ' * (all_full - num_hashes) + ']'
25        pct_place = (len(self.prog_bar) / 2) - len(str(percent_done))
26        pct_string = '%i%%' % percent_done
27        self.prog_bar = self.prog_bar[0:pct_place] + \
28            (pct_string + self.prog_bar[pct_place + len(pct_string):])
29       
30    def update_time(self, elapsed_secs):
31        self.__update_amount((elapsed_secs / float(self.duration)) * 100.0)
32        self.prog_bar += '  %ds/%ss' % (elapsed_secs, self.duration)
33       
34    def __str__(self):
35        return str(self.prog_bar)
Note: See TracBrowser for help on using the repository browser.