hamster: new state
@@ -16,8 +16,7 @@ Requires:
@license BSD
"""
-STRING_NOT_INSTALLED = "hamster: isn't installed"
-STRING_ERROR = "hamster: unknown error"
+STRING_NOT_INSTALLED = "isn't installed"
class Py3status:
@@ -27,31 +26,23 @@ class Py3status:
cache_timeout = 10
format = '{current}'
- def hamster(self):
+ def post_config_hook(self):
if not self.py3.check_commands('hamster'):
- return {
- 'cached_until': self.py3.CACHE_FOREVER,
- 'color': self.py3.COLOR_BAD,
- 'full_text': STRING_NOT_INSTALLED
- }
- try:
- cur_task = self.py3.command_output('hamster current').strip()
- except:
+ raise Exception(STRING_NOT_INSTALLED)
+
+ def hamster(self):
+ activity = self.py3.command_output('hamster current').strip()
+ if activity != 'No activity':
+ activity = activity.split()
+ time_elapsed = activity[-1]
+ activity = activity[2:-1]
+ activity = u"%s (%s)" % (" ".join(activity), time_elapsed)
+
return {
'cached_until': self.py3.time_in(self.cache_timeout),
- 'color': self.py3.COLOR_BAD,
- 'full_text': STRING_ERROR
+ 'full_text': self.py3.safe_format(self.format, {'current': activity})
}
- if cur_task != 'No activity':
- cur_task = cur_task.split()
- time_elapsed = cur_task[-1]
- cur_task = cur_task[2:-1]
- cur_task = u"%s (%s)" % (" ".join(cur_task), time_elapsed)
-
- return {'cached_until': self.py3.time_in(self.cache_timeout),
- 'full_text': self.py3.safe_format(self.format, {'current': cur_task})}
-
if __name__ == "__main__":
"""
