[modules/time] Add parameter for format string

Format string for strftime is now configurable. Also, changed the
separator for module name vs. arguments to "::" to make it possible to
have ":" as part of the strftime format string (which is useful in most
cases).

Eventually, I'll probably have to come up with a better way, i.e. a
fully-fledged parser, and move away from "special characters", but right
now, the effort seems too much for the gain.
This commit is contained in:
Tobias Witek 2016-10-31 10:53:31 +01:00
parent 2a35905b89
commit 00c92cb9e3
2 changed files with 4 additions and 3 deletions

View file

@ -3,9 +3,10 @@ import bumblebee.module
class Module(bumblebee.module.Module):
def __init__(self, args):
self._fmt = args[0] if args else "%x %X"
super(Module, self).__init__(args)
def data(self):
return datetime.datetime.now().strftime("%x %X")
return datetime.datetime.now().strftime(self._fmt)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -27,8 +27,8 @@ def main():
for m in args.modules:
# TODO: how to cleanly handle errors here?
# (useful error messages)
module_name = m if not ":" in m else m.split(":")[0]
module_args = None if not ":" in m else m.split(":")[1:]
module_name = m if not "::" in m else m.split("::")[0]
module_args = None if not "::" in m else m.split("::")[1:]
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
modules.append(getattr(module, "Module")(module_args))