[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:
parent
2a35905b89
commit
00c92cb9e3
2 changed files with 4 additions and 3 deletions
|
@ -3,9 +3,10 @@ import bumblebee.module
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
self._fmt = args[0] if args else "%x %X"
|
||||||
super(Module, self).__init__(args)
|
super(Module, self).__init__(args)
|
||||||
|
|
||||||
def data(self):
|
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
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -27,8 +27,8 @@ def main():
|
||||||
for m in args.modules:
|
for m in args.modules:
|
||||||
# TODO: how to cleanly handle errors here?
|
# TODO: how to cleanly handle errors here?
|
||||||
# (useful error messages)
|
# (useful error messages)
|
||||||
module_name = m if not ":" in m else m.split(":")[0]
|
module_name = m if not "::" in m else m.split("::")[0]
|
||||||
module_args = None if not ":" in m else m.split(":")[1:]
|
module_args = None if not "::" in m else m.split("::")[1:]
|
||||||
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
|
module = importlib.import_module("bumblebee.modules.{}".format(module_name))
|
||||||
modules.append(getattr(module, "Module")(module_args))
|
modules.append(getattr(module, "Module")(module_args))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue