]> git.madduck.net Git - etc/taskwarrior.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

on-add-pirate: Initial implementation
authorTomas Babej <tomasbabej@gmail.com>
Tue, 7 Apr 2015 15:23:12 +0000 (17:23 +0200)
committerTomas Babej <tomasbabej@gmail.com>
Tue, 7 Apr 2015 15:23:12 +0000 (17:23 +0200)
on-add-pirate [new file with mode: 0755]
pirate_add/__init__.py [new file with mode: 0644]
pirate_add/example.py [new file with mode: 0644]

diff --git a/on-add-pirate b/on-add-pirate
new file mode 100755 (executable)
index 0000000..1484083
--- /dev/null
@@ -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 (file)
index 0000000..cdeb845
--- /dev/null
@@ -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 (file)
index 0000000..3e4e41f
--- /dev/null
@@ -0,0 +1,2 @@
+def hook_example(task):
+    task['description'] += "This was altered by hook"