-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusupdate.py
executable file
·66 lines (45 loc) · 1.95 KB
/
statusupdate.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import sys
def clearLine():
# Clear whatever might be already written on the current line
# to the left using backspaces.
# Not enough backspaces means we don't erase all the text. Too many
# doesn't really hurt?
clearstring = " \b\b" * 20
print(clearstring * 10,end="")
def writeElapsed(seconds):
# Convert number of seconds elapsed to hours, minutes and seconds,
# and display this info formatted to the screen.
hoursElapsed = int ( seconds / 60 / 60 )
minutesElapsed = int( ( seconds - ( hoursElapsed * 60 * 60 ) ) / 60 )
secondsElapsed = int( seconds - (hoursElapsed * 60 * 60) - ( minutesElapsed * 60 ) )
print("[%02i:%02i:%02i]" % (hoursElapsed, minutesElapsed, secondsElapsed), end="")
def writeSeparator():
print(" ", end="")
def writePhase(phaseNum, phaseTotal, phaseLabel):
print("(%i/%i) %s"%(phaseNum, phaseTotal, phaseLabel), end="")
def updateLine(seconds, phaseNum, phaseTotal, phaseLabel, subphaseNum=None, subphaseTotal=None, subphaseLabel=None, overwrite=True):
if overwrite:
clearLine()
writeElapsed(seconds)
writeSeparator()
writePhase(phaseNum, phaseTotal, phaseLabel)
if subphaseTotal != None:
writeSeparator()
writePhase(subphaseNum, subphaseTotal, subphaseLabel)
if not overwrite:
print()
if __name__ == "__main__":
overwrite = False
sys.stderr.write(" ".join(sys.argv) + "\n")
secondsDuration = int( sys.argv[1] )
phaseTotal = int(sys.argv[2])
phaseNumber = int(sys.argv[3])
phaseName = sys.argv[4]
if len(sys.argv) > 6:
subphaseTotal = int(sys.argv[5])
subphase = int(sys.argv[6])
subphaseLabel = sys.argv[7]
updateLine(secondsDuration, phaseNumber, phaseTotal, phaseName, subphase, subphaseTotal, subphaseLabel, overwrite=overwrite)
else:
updateLine(secondsDuration, phaseNumber, phaseTotal, phaseName, overwrite=overwrite)