From 0899c6516bd9bf8fdd4bd973106eaa1ffcf67667 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Tue, 7 Apr 2015 18:34:34 +0200 Subject: [PATCH] Add pirate-enabled version of the hook --- pirate_add_shift_recurrence.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pirate_add_shift_recurrence.py diff --git a/pirate_add_shift_recurrence.py b/pirate_add_shift_recurrence.py new file mode 100644 index 0000000..723dfdb --- /dev/null +++ b/pirate_add_shift_recurrence.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import sys +import os +from tasklib.task import Task, TaskWarrior + +time_attributes = ('wait', 'until', '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]))) + +def hook_shift_recurrence(task): + if is_new_local_recurrence_child_task(task): + parent = tw.tasks.get(uuid=task['parent']) + parent_due_shift = task['due'] - parent['due'] + for attr in time_attributes: + if parent[attr]: + task[attr] = parent[attr] + parent_due_shift -- 2.39.5