i3pystatus/i3pystatus/makewatch.py
enkore 612b8b07eb Update modules to a7583a9
Not updated for various reasons:
clock,
dpms,
gpu_temp,
load,
mail,
mem_bar,
modsde,
net_speed,
pianobar,
pulseaudio,
regex [no named formatters],
runwatch,
shell,
solaar,
temp,
text,
updates,
weather,
whosonlocation,
xkblayout,
zabbix


This might break something: I can't test all these modules. If it does,
file a bug / open a PR / send me a note.
2016-01-27 19:53:33 +01:00

46 lines
1.2 KiB
Python

from i3pystatus import IntervalModule
import psutil
import getpass
class MakeWatch(IntervalModule):
"""
Watches for make jobs and notifies when they are completed.
requires: psutil
"""
settings = (
("name", "Listen for a job other than 'make' jobs"),
("running_color", "Text color while the job is running"),
("idle_color", "Text color while the job is not running"),
"format",
)
running_color = "#FF0000" # red
idle_color = "#00FF00" # green
name = 'make'
format = "{name}: {status}"
def run(self):
status = 'idle'
for proc in psutil.process_iter():
cur_proc = proc.as_dict(attrs=['name', 'username'])
if getpass.getuser() in cur_proc['username']:
if cur_proc['name'] == self.name:
status = proc.as_dict(attrs=['status'])['status']
if status == 'idle':
color = self.idle_color
else:
color = self.running_color
cdict = {
"name": self.name,
"status": status
}
self.data = cdict
self.output = {
"full_text": self.format.format(**cdict),
"color": color
}