27 lines
720 B
Python
Executable file
27 lines
720 B
Python
Executable file
#! /usr/bin/env python3
|
|
# encoding: utf-8
|
|
|
|
import psutil
|
|
|
|
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_x, pos_y = [int(a) for a in position.split(" of ")]
|
|
|
|
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]
|
|
|
|
yield "%s %s (%s, %.01f %%)" %(action, atom, position, 100 * pos_x / pos_y)
|
|
|
|
if __name__ == "__main__":
|
|
for state in cave_stat():
|
|
print(state)
|