makewatch: a module to watch for make (or other long running) jobs
A module that will watch for (by default) make jobs and notify of their status. This can be used for other long-running processes by providing an alternate 'name'.
This commit is contained in:
parent
317d96b176
commit
7be136167d
@ -32,7 +32,7 @@ MOCK_MODULES = [
|
|||||||
"requests",
|
"requests",
|
||||||
"bs4",
|
"bs4",
|
||||||
"novaclient.v2",
|
"novaclient.v2",
|
||||||
"dota2py",
|
"psutil", "getpass"
|
||||||
]
|
]
|
||||||
|
|
||||||
for mod_name in MOCK_MODULES:
|
for mod_name in MOCK_MODULES:
|
||||||
|
45
i3pystatus/makewatch.py
Normal file
45
i3pystatus/makewatch.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from i3pystatus import IntervalModule
|
||||||
|
import psutil
|
||||||
|
import getpass
|
||||||
|
|
||||||
|
|
||||||
|
class MakeWatch(IntervalModule):
|
||||||
|
"""
|
||||||
|
Watches for make jobs and notifies when they are completed.
|
||||||
|
requires: psutil
|
||||||
|
"""
|
||||||
|
|
||||||
|
settings = (
|
||||||
|
("user", "Specifies which user to track. Null means all users"),
|
||||||
|
("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", "idle_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.output = {
|
||||||
|
"full_text": self.format.format(**cdict),
|
||||||
|
"color": color
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user