made cave-stat even awesomer
This commit is contained in:
parent
98e4270b26
commit
d14716de65
1 changed files with 18 additions and 2 deletions
|
@ -1,7 +1,15 @@
|
|||
#! /usr/bin/env python3
|
||||
# encoding: utf-8
|
||||
|
||||
import over
|
||||
import psutil
|
||||
import re
|
||||
|
||||
def safe_int(s):
|
||||
try:
|
||||
return int(s)
|
||||
except:
|
||||
return 0
|
||||
|
||||
def cave_stat():
|
||||
for proc in psutil.process_iter():
|
||||
|
@ -10,7 +18,7 @@ def cave_stat():
|
|||
|
||||
if "--x-of-y" in cmdline:
|
||||
position = [c for c in cmdline if " of " in c][0]
|
||||
pos_x, pos_y = [int(a) for a in position.split(" of ")]
|
||||
pos, total, failed = [safe_int(a) for a in re.findall("(\d+) of (\d+)(?:, (\d+) failed)?", position)[0]]
|
||||
|
||||
if "--destination" in cmdline:
|
||||
action = "Installing"
|
||||
|
@ -20,7 +28,15 @@ def cave_stat():
|
|||
action = "Downloading"
|
||||
atom = [c for c in cmdline if "::" in c and c[0] == "="][0]
|
||||
|
||||
yield "%s %s (%s, %.01f %%)" %(action, atom, position, 100 * pos_x / pos_y)
|
||||
lines = [
|
||||
"<G>*<.> %s <W>%s<.>" %(action, atom),
|
||||
" - %s of %s (<g>%.01f %%<.>)" %(pos, total, 100 * int(pos) / int(total))
|
||||
]
|
||||
|
||||
if failed:
|
||||
lines.append(" - <R>%d <r>failed<.>, %.01f %% failure rate" %(failed, 100 * failed / total))
|
||||
|
||||
yield over.text.render("\n".join(lines))
|
||||
|
||||
if __name__ == "__main__":
|
||||
for state in cave_stat():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue