bumblebee-status/modules/contrib/watson.py

57 lines
1.4 KiB
Python
Raw Normal View History

2020-04-19 14:23:41 +02:00
# pylint: disable=C0111,R0903
"""Displays the status of watson (time-tracking tool)
Requires the following executable:
* watson
"""
import logging
import re
import functools
2020-04-19 14:27:11 +02:00
import core.module
import core.widget
import core.input
import core.decorators
import util.cli
class Module(core.module.Module):
@core.decorators.every(minutes=60)
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.text))
2020-04-19 14:27:11 +02:00
self.__tracking = False
self.__project = ''
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle)
2020-04-19 14:23:41 +02:00
def toggle(self, widget):
2020-04-19 14:27:11 +02:00
self.__project = 'hit'
if self.__tracking:
util.cli.execute('watson stop')
2020-04-19 14:23:41 +02:00
else:
2020-04-19 14:27:11 +02:00
util.cli.execute('watson restart')
self.__tracking = not self.__tracking
2020-04-19 14:23:41 +02:00
def text(self, widget):
2020-04-19 14:27:11 +02:00
if self.__tracking:
return self.__project
2020-04-19 14:23:41 +02:00
else:
2020-04-19 14:24:00 +02:00
return 'Paused'
2020-04-19 14:23:41 +02:00
2020-04-19 14:27:11 +02:00
def update(self):
output = util.cli.execute('watson status')
2020-04-19 14:23:41 +02:00
if re.match('No project started', output):
2020-04-19 14:27:11 +02:00
self.__tracking = False
2020-04-19 14:23:41 +02:00
return
2020-04-19 14:27:11 +02:00
self.__tracking = True
2020-04-19 14:23:41 +02:00
m = re.search(r'Project (.+) started', output)
2020-04-19 14:27:11 +02:00
self.__project = m.group(1)
2020-04-19 14:23:41 +02:00
def state(self, widget):
2020-04-19 14:27:11 +02:00
return 'on' if self.__tracking else 'off'
2020-04-19 14:23:41 +02:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4