4e648cf009
Big oversight in my previous commits: Widgets need to be able to have specific configurations (i.e. the path for different instances of the "disk" module has to be different). To account for that, it is now possible to assign an "alias" to a module instance using ":" (for example: -m "disk:home"). This alias is then used for the configuration parameter resolution automatically, for example: -m disk:home -p home.path=/home As a consequence, parameter names in the module code are now relative to the module, which means: shorter!
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from __future__ import absolute_import
|
|
|
|
import datetime
|
|
import bumblebee.module
|
|
|
|
def usage():
|
|
module = __name__.split(".")[-1]
|
|
if module == "date":
|
|
return "date::<strftime format string, defaults to %x>"
|
|
if module == "time":
|
|
return "time::<strftime format string, defaults to %X>"
|
|
return "datetime::<strftime format string, defaults to '%x %X'>"
|
|
|
|
def notes():
|
|
return "none"
|
|
|
|
def description():
|
|
return "Displays the current time, using the optional format string as input for strftime."
|
|
|
|
class Module(bumblebee.module.Module):
|
|
def __init__(self, output, config, alias):
|
|
super(Module, self).__init__(output, config, alias)
|
|
|
|
module = self.__module__.split(".")[-1]
|
|
default = "%x %X"
|
|
if module == "date":
|
|
default = "%x"
|
|
if module == "time":
|
|
default = "%X"
|
|
|
|
self._fmt = config.parameter("format", default)
|
|
|
|
def widgets(self):
|
|
return bumblebee.output.Widget(self, datetime.datetime.now().strftime(self._fmt))
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|