Debian Codegraph @

cclib/progress/textprogress.py

raw
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.
7
8 from __future__ import print_function
9
10 import sys
11
12
13 class TextProgress:
14
15 def __init__(self):
16
17 self.nstep = 0
18 self.text = None
19 self.oldprogress = 0
20 self.progress = 0
21 self.calls = 0
22
23 def initialize(self, nstep, text=None):
24
25 self.nstep = float(nstep)
26 self.text = text
27
28 #sys.stdout.write("\n")
29
30 def update(self, step, text=None):
31
32 self.progress = int(step * 100 / self.nstep)
33
34 if self.progress/2 >= self.oldprogress/2 + 1 or self.text != text:
35 # just went through at least an interval of ten, ie. from 39 to 41,
36 # so update
37
38 mystr = "\r["
39 prog = int(self.progress / 10)
40 mystr += prog * "=" + (10-prog) * "-"
41 mystr += "] %3i" % self.progress + "%"
42
43 if text:
44 mystr += " "+text
45
46 sys.stdout.write("\r" + 70 * " ")
47 sys.stdout.flush()
48 sys.stdout.write(mystr)
49 sys.stdout.flush()
50 self.oldprogress = self.progress
51
52 if self.progress >= 100 and text == "Done":
53 print(" ")
54
55 return