FUNCTION: this module prints a progress bar to show how much time you have to wait until the program finish. It simply reads a percentage to update the progress bar.
USAGE: from progressBar import progressBar bar = progressBar(min=0, max=200, barLength=None, output=sys.stderr) for i in range(200): bar.update(i) time.sleep(0.1)
# === classes === class progressBar: def __init__(self, min = 0, max = 100, barLength = None, output=sys.stderr): self.output = output self.progBar = "[]" # This holds the progress bar string self.min = min self.max = max - 1 self.span = self.max - self.min + 1 self.barLength = self.calBarLength(barLength) self.percentDone = 0 self.timeStart = time.time() self.timePrevious = self.timeStart self.timePass = 0 self.finish = False self.update(0) # Build progress bar string
def calBarLength(self, barLength): if barLength == None: from fcntl import ioctl from termios import TIOCGWINSZ from array import array a = ioctl(self.output,TIOCGWINSZ,'\0'*8) h,w=array('h',a)[:2] return w else: return barLength
# Figure out how many '=' and spaces the bar should be spaceAndEqual = self.barLength - 11 - len(printETA) numEqual = (self.percentDone / 100.0) * spaceAndEqual numEqual = int(round(numEqual))