]> git.madduck.net Git - etc/taskwarrior.git/blob - on-add-pirate

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:

Remove example hook
[etc/taskwarrior.git] / on-add-pirate
1 #!/usr/bin/python
2
3 import glob
4 import imp
5 import os
6
7 from tasklib.task import TaskWarrior, Task
8
9
10 def find_hooks(file_prefix):
11     # Find all files in subdirectories whose names start with <file_prefix>
12     file_pattern = os.path.dirname(__file__) + '/*/' + file_prefix + "*.py"
13     module_paths = [f for f in glob.glob(file_pattern) if os.path.isfile(f)]
14
15     # Gather all hooks in these files
16     hooks = []
17
18     for module_path in module_paths:
19         # Load the module
20         module_dir = os.path.dirname(module_path)
21         module_filename = os.path.basename(module_path)
22         module_name = 'pirate_{0}_{1}'.format(module_dir, module_filename)
23         module = imp.load_source(module_name, module_path)
24
25         # Find all hook methods available
26         module_hooks = [
27             getattr(module, hook_name)
28             for hook_name in dir(module)
29             if hook_name.startswith('hook_')
30         ]
31
32         hooks += module_hooks
33
34     return hooks
35
36 task = Task.from_input()
37
38 for hook in find_hooks('pirate_add'):
39     hook(task)
40
41 print task.export_data()