43 lines
1.1 KiB
Python
Executable file
43 lines
1.1 KiB
Python
Executable file
#! /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():
|
|
if proc.name() == "cave":
|
|
cmdline = proc.cmdline()
|
|
|
|
if "--x-of-y" in cmdline:
|
|
position = [c for c in cmdline if " of " in c][0]
|
|
pos, total, failed = [safe_int(a) for a in re.findall("(\d+) of (\d+)(?:, (\d+) failed)?", position)[0]]
|
|
|
|
if "--destination" in cmdline:
|
|
action = "Installing"
|
|
atom_idx = cmdline.index("--destination") - 1
|
|
atom = cmdline[atom_idx]
|
|
else:
|
|
action = "Downloading"
|
|
atom = [c for c in cmdline if "::" in c and c[0] == "="][0]
|
|
|
|
lines = [
|
|
"<B>**<.> %s <W>%s<.>" %(action, atom),
|
|
" - <G>%s of %s <g>done<.> (%.01f %% remaining)" %(pos, total, 100 - 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():
|
|
print(state)
|