]> git.madduck.net Git - etc/taskwarrior.git/blob - on-add-shift-all-recurrence

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:

Detect data location and do not nest recurrence generation
[etc/taskwarrior.git] / on-add-shift-all-recurrence
1 #!/usr/bin/python
2
3 import sys
4 import os
5 from tasklib.task import Task, TaskWarrior
6
7 time_attributes = ('wait', 'until', 'scheduled')
8
9 def is_new_local_recurrence_child_task(task):
10     # Do not affect tasks not spun by recurrence
11     if not task['parent']:
12         return False
13
14     # Newly created recurrence tasks actually have
15     # modified field copied from the parent, thus
16     # older than entry field (until their ID is generated)
17     if (task['modified'] - task['entry']).total_seconds() < 0:
18         return True
19
20 task = Task.from_input()
21 tw = TaskWarrior(data_location=os.path.dirname(os.path.dirname(sys.argv[0])))
22 tw.config.update(dict(recurrence="no"))
23
24 if is_new_local_recurrence_child_task(task):
25     parent = tw.tasks.get(uuid=task['parent'])
26     parent_due_shift = task['due'] - parent['due']
27     for attr in time_attributes:
28         if parent[attr]:
29             task[attr] = parent[attr] + parent_due_shift
30
31 print task.export_data()