diff --git a/docs/conf.py b/docs/conf.py index 178c85f..c45ffd7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,7 +32,7 @@ MOCK_MODULES = [ "requests", "bs4", "novaclient.v2", - "dota2py", + "psutil", "getpass" ] for mod_name in MOCK_MODULES: diff --git a/i3pystatus/makewatch.py b/i3pystatus/makewatch.py new file mode 100644 index 0000000..ca236c3 --- /dev/null +++ b/i3pystatus/makewatch.py @@ -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 + }