From 5c644d93c7d57956db63135296e653c6f66ec9e7 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Tue, 7 Apr 2015 17:23:12 +0200 Subject: [PATCH 1/1] on-add-pirate: Initial implementation --- on-add-pirate | 11 +++++++++++ pirate_add/__init__.py | 18 ++++++++++++++++++ pirate_add/example.py | 2 ++ 3 files changed, 31 insertions(+) create mode 100755 on-add-pirate create mode 100644 pirate_add/__init__.py create mode 100644 pirate_add/example.py 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" -- 2.39.5