[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / lldb / third_party / Python / module / progress / progress.py
blobf844b9800c019234be13b58303079aa16b655a58
1 #!/usr/bin/env python
3 import use_lldb_suite
5 import sys
6 import time
9 class ProgressBar(object):
10 """ProgressBar class holds the options of the progress bar.
11 The options are:
12 start State from which start the progress. For example, if start is
13 5 and the end is 10, the progress of this state is 50%
14 end State in which the progress has terminated.
15 width --
16 fill String to use for "filled" used to represent the progress
17 blank String to use for "filled" used to represent remaining space.
18 format Format
19 incremental
20 """
21 light_block = chr(0x2591).encode("utf-8")
22 solid_block = chr(0x2588).encode("utf-8")
23 solid_right_arrow = chr(0x25BA).encode("utf-8")
25 def __init__(self,
26 start=0,
27 end=10,
28 width=12,
29 fill=chr(0x25C9).encode("utf-8"),
30 blank=chr(0x25CC).encode("utf-8"),
31 marker=chr(0x25CE).encode("utf-8"),
32 format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
33 incremental=True):
34 super(ProgressBar, self).__init__()
36 self.start = start
37 self.end = end
38 self.width = width
39 self.fill = fill
40 self.blank = blank
41 self.marker = marker
42 self.format = format
43 self.incremental = incremental
44 self.step = 100 / float(width) # fix
45 self.reset()
47 def __add__(self, increment):
48 increment = self._get_progress(increment)
49 if 100 > self.progress + increment:
50 self.progress += increment
51 else:
52 self.progress = 100
53 return self
55 def complete(self):
56 self.progress = 100
57 return self
59 def __str__(self):
60 progressed = int(self.progress / self.step) # fix
61 fill = progressed * self.fill
62 blank = (self.width - progressed) * self.blank
63 return self.format % {
64 'fill': fill,
65 'blank': blank,
66 'marker': self.marker,
67 'progress': int(
68 self.progress)}
70 __repr__ = __str__
72 def _get_progress(self, increment):
73 return float(increment * 100) / self.end
75 def reset(self):
76 """Resets the current progress to the start point"""
77 self.progress = self._get_progress(self.start)
78 return self
81 class AnimatedProgressBar(ProgressBar):
82 """Extends ProgressBar to allow you to use it straighforward on a script.
83 Accepts an extra keyword argument named `stdout` (by default use sys.stdout)
84 and may be any file-object to which send the progress status.
85 """
87 def __init__(self,
88 start=0,
89 end=10,
90 width=12,
91 fill=chr(0x25C9).encode("utf-8"),
92 blank=chr(0x25CC).encode("utf-8"),
93 marker=chr(0x25CE).encode("utf-8"),
94 format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
95 incremental=True,
96 stdout=sys.stdout):
97 super(
98 AnimatedProgressBar,
99 self).__init__(
100 start,
101 end,
102 width,
103 fill,
104 blank,
105 marker,
106 format,
107 incremental)
108 self.stdout = stdout
110 def show_progress(self):
111 if hasattr(self.stdout, 'isatty') and self.stdout.isatty():
112 self.stdout.write('\r')
113 else:
114 self.stdout.write('\n')
115 self.stdout.write(str(self))
116 self.stdout.flush()
119 class ProgressWithEvents(AnimatedProgressBar):
120 """Extends AnimatedProgressBar to allow you to track a set of events that
121 cause the progress to move. For instance, in a deletion progress bar, you
122 can track files that were nuked and files that the user doesn't have access to
125 def __init__(self,
126 start=0,
127 end=10,
128 width=12,
129 fill=chr(0x25C9).encode("utf-8"),
130 blank=chr(0x25CC).encode("utf-8"),
131 marker=chr(0x25CE).encode("utf-8"),
132 format='[%(fill)s%(marker)s%(blank)s] %(progress)s%%',
133 incremental=True,
134 stdout=sys.stdout):
135 super(
136 ProgressWithEvents,
137 self).__init__(
138 start,
139 end,
140 width,
141 fill,
142 blank,
143 marker,
144 format,
145 incremental,
146 stdout)
147 self.events = {}
149 def add_event(self, event):
150 if event in self.events:
151 self.events[event] += 1
152 else:
153 self.events[event] = 1
155 def show_progress(self):
156 isatty = hasattr(self.stdout, 'isatty') and self.stdout.isatty()
157 if isatty:
158 self.stdout.write('\r')
159 else:
160 self.stdout.write('\n')
161 self.stdout.write(str(self))
162 if len(self.events) == 0:
163 return
164 self.stdout.write('\n')
165 for key in list(self.events.keys()):
166 self.stdout.write(str(key) + ' = ' + str(self.events[key]) + ' ')
167 if isatty:
168 self.stdout.write('\033[1A')
169 self.stdout.flush()
172 if __name__ == '__main__':
173 p = AnimatedProgressBar(end=200, width=200)
175 while True:
176 p + 5
177 p.show_progress()
178 time.sleep(0.3)
179 if p.progress == 100:
180 break
181 print() # new line