X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/blobdiff_plain/09f6572d50f43509715cd634b47c6e2cd5afe944..a8767d0e7ed2339be98c6244ead25d63034f85b9:/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py diff --git a/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py b/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py new file mode 100644 index 0000000..0266fc5 --- /dev/null +++ b/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +import sys +import os +from tasklib import TaskWarrior + +time_attributes = ('wait', 'scheduled') + +def is_new_local_recurrence_child_task(task): + # Do not affect tasks not spun by recurrence + if not task['parent']: + return False + + # Newly created recurrence tasks actually have + # modified field copied from the parent, thus + # older than entry field (until their ID is generated) + if (task['modified'] - task['entry']).total_seconds() < 0: + return True + +tw = TaskWarrior(data_location=os.path.dirname(os.path.dirname(sys.argv[0]))) +tw.overrides.update(dict(recurrence="no", hooks="no")) + +def hook_shift_recurrence(task): + if is_new_local_recurrence_child_task(task): + parent = tw.tasks.get(uuid=task['parent']['uuid']) + parent_due_shift = task['due'] - parent['due'] + for attr in time_attributes: + if parent[attr]: + task[attr] = parent[attr] + parent_due_shift