-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (25 loc) · 844 Bytes
/
utils.py
File metadata and controls
35 lines (25 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
def is_power_of_2(n):
assert isinstance(n, int)
return (n & (n - 1) == 0) and (n != 0)
print_width = 50
def fancy_horizontal_rule():
sys.stdout.write("|" + "-" * (print_width - 2) + "|\n")
sys.stdout.flush()
def fancy_print(contents=None):
if contents is None:
contents = ""
n = len(contents)
l = " " * ((print_width - 2 - n) // 2)
m = max(0, print_width - 2 - len(l) - len(contents))
r = " " * m
sys.stdout.write("|" + l + contents + r + "|\n")
sys.stdout.flush()
def progress_bar(current, total):
i = current + 1
if (not sys.stdout.isatty()) and (i < total):
return
bar_fill = "=" * (i * 50 // total)
end_of_line = "\n" if (i == total) else ""
sys.stdout.write("\r[%-50s] %d/%d%s" % (bar_fill, i, total, end_of_line))
sys.stdout.flush()