From: Tomas Babej Date: Tue, 7 Apr 2015 15:23:12 +0000 (+0200) Subject: on-add-pirate: Initial implementation X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/5c644d93c7d57956db63135296e653c6f66ec9e7?hp=042747a9594a1752967c9929a4671297864c4016 on-add-pirate: Initial implementation --- diff --git a/on-add-pirate b/on-add-pirate new file mode 100755 index 0000000..1484083 --- /dev/null +++ b/on-add-pirate @@ -0,0 +1,11 @@ +#!/usr/bin/python + +from tasklib.task import TaskWarrior, Task +import pirate_add + +task = Task.from_input() + +for hook in pirate_add.hooks: + hook(task) + +print task.export_data() diff --git a/pirate_add/__init__.py b/pirate_add/__init__.py new file mode 100644 index 0000000..cdeb845 --- /dev/null +++ b/pirate_add/__init__.py @@ -0,0 +1,18 @@ +import os +import glob +import importlib + +__all__ = [os.path.basename(f)[:-3] + for f in glob.glob(os.path.dirname(__file__)+"/*.py") + if os.path.isfile(f) and not os.path.basename(f).startswith('_')] + +hooks = [] + +for module_name in __all__: + module = importlib.import_module('pirate_add.%s' % module_name) + module_hooks = [ + getattr(module, hook_name) + for hook_name in dir(module) + if hook_name.startswith('hook_') + ] + hooks += module_hooks diff --git a/pirate_add/example.py b/pirate_add/example.py new file mode 100644 index 0000000..3e4e41f --- /dev/null +++ b/pirate_add/example.py @@ -0,0 +1,2 @@ +def hook_example(task): + task['description'] += "This was altered by hook"