]> git.madduck.net Git - etc/taskwarrior.git/blob - on-modify-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:

LICENCE: Update copyright
[etc/taskwarrior.git] / on-modify-pirate
1 #!/usr/bin/python
2
3 import glob
4 import imp
5 import os
6
7 from tasklib 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     module_paths.sort()
15
16     # Gather all hooks in these files
17     hooks = []
18
19     for module_path in module_paths:
20         # Load the module
21         module_dir = os.path.dirname(module_path)
22         module_filename = os.path.basename(module_path)
23         module_name = 'pirate_{0}_{1}'.format(module_dir, module_filename)
24         module_name = module_name.replace('.', '_')
25         module = imp.load_source(module_name, module_path)
26
27         # Find all hook methods available
28         module_hooks = [
29             getattr(module, hook_name)
30             for hook_name in dir(module)
31             if hook_name.startswith('hook_')
32         ]
33
34         hooks += module_hooks
35
36     return hooks
37
38 task = Task.from_input()
39
40 for hook in find_hooks('pirate_mod'):
41     hook(task)
42
43 print(task.export_data())