diff --git a/bin/cave-stat b/bin/cave-stat index 2fe158e..4d97d4e 100755 --- a/bin/cave-stat +++ b/bin/cave-stat @@ -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 = [ + "*<.> %s %s<.>" %(action, atom), + " - %s of %s (%.01f %%<.>)" %(pos, total, 100 * int(pos) / int(total)) + ] + + if failed: + lines.append(" - %d failed<.>, %.01f %% failure rate" %(failed, 100 * failed / total)) + + yield over.text.render("\n".join(lines)) if __name__ == "__main__": for state in cave_stat():