Coverage for cclib/progress/textprogress.py : 18%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#
3# Copyright (c) 2017, the cclib development team
4#
5# This file is part of cclib (http://cclib.github.io) and is distributed under
6# the terms of the BSD 3-Clause License.
8import sys
11class TextProgress:
13 def __init__(self):
15 self.nstep = 0
16 self.text = None
17 self.oldprogress = 0
18 self.progress = 0
19 self.calls = 0
21 def initialize(self, nstep, text=None):
23 self.nstep = float(nstep)
24 self.text = text
26 #sys.stdout.write("\n")
28 def update(self, step, text=None):
30 self.progress = int(step * 100 / self.nstep)
32 if self.progress/2 >= self.oldprogress/2 + 1 or self.text != text:
33 # just went through at least an interval of ten, ie. from 39 to 41,
34 # so update
36 mystr = "\r["
37 prog = int(self.progress / 10)
38 mystr += prog * "=" + (10-prog) * "-"
39 mystr += "] %3i" % self.progress + "%"
41 if text:
42 mystr += " "+text
44 sys.stdout.write("\r" + 70 * " ")
45 sys.stdout.flush()
46 sys.stdout.write(mystr)
47 sys.stdout.flush()
48 self.oldprogress = self.progress
50 if self.progress >= 100 and text == "Done":
51 print(" ")
53 return