From e2790fbf6e3a55af4d7b603c84505d001c2e6670 Mon Sep 17 00:00:00 2001 From: Kevin Fong Date: Sun, 24 Sep 2017 16:11:40 -0700 Subject: [PATCH 1/3] Save modifications --- on-modify.relative-recur | 80 +++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/on-modify.relative-recur b/on-modify.relative-recur index 67335b4..b0edebd 100755 --- a/on-modify.relative-recur +++ b/on-modify.relative-recur @@ -1,4 +1,5 @@ #!/usr/bin/env python +# https://github.com/JensErat/task-relative-recur from __future__ import print_function from builtins import str @@ -21,10 +22,10 @@ env['TZ'] = 'UTC0' # Hand back duration format parsing to task warrior def calc(statement): - calc = subprocess.Popen(['task', 'rc.verbose=nothing', 'rc.date.iso=yes', 'calc', statement], stdout=subprocess.PIPE, env=env) - out, err = calc.communicate() - # Workaround for TW-1254 (https://bug.tasktools.org/browse/TW-1254) - return out.decode("utf-8").rstrip().replace('-', '').replace(':', '') + 'Z' + calc = subprocess.Popen(['task', 'rc.verbose=nothing', 'rc.date.iso=yes', 'calc', statement], stdout=subprocess.PIPE, env=env) + out, err = calc.communicate() + # Workaround for TW-1254 (https://bug.tasktools.org/browse/TW-1254) + return out.decode("utf-8").rstrip().replace('-', '').replace(':', '') + 'Z' # Parse the modified task original = json.loads(sys.stdin.readline()) @@ -35,39 +36,44 @@ modified = json.loads(modified) # Has a task with UDA been marked as completed? if (UDA_DUE in original or UDA_WAIT in original) and original['status']!='completed' and modified['status']=='completed': - del original['modified'] - if 'start' in original: - del original['start'] - if UDA_DUE in original: - original['due'] = calc(modified['end'] + '+' + original[UDA_DUE]) - if UDA_WAIT in original: - original['wait'] = calc(modified['end'] + '+' + original[UDA_WAIT]) - original['status'] = 'waiting' - else: - original['status'] = 'pending' - print('Created follow-up task') - original['entry'] = modified['end'] - original['uuid'] = str(uuid.uuid4()) + del original['modified'] - # Wait for taskwarrior to finish, so we can safely `task import` the new task - sys.stdout.flush() - task_pid = os.getppid() - if (0 < os.fork()): - sys.exit(0) - else: - # Taskwarrior also waits for stdout to close - try: - os.close(sys.stdout.fileno()) - except OSError: - pass # Thrown because of closing stdout. Don't worry, that's fine. + if 'totalactivetime' in original: + del original['totalactivetime'] + if 'start' in original: + del original['start'] + if UDA_DUE in original: + original['due'] = calc(modified['end'] + '+' + original[UDA_DUE]) + if UDA_WAIT in original: + original['wait'] = calc(modified['end'] + '+' + original[UDA_WAIT]) + original['scheduled'] = calc(modified['end'] + '+' + original[UDA_WAIT]) + original['status'] = 'waiting' - # Wait for taskwarrior to finish - while (os.path.exists("/proc/%s" % str(task_pid))): - time.sleep(0.25) + else: + original['status'] = 'pending' + print('Created follow-up task') + original['entry'] = modified['end'] + original['uuid'] = str(uuid.uuid4()) - # Import the follow-up task - with tempfile.NamedTemporaryFile(mode="wt") as new_task: - new_task.write(json.dumps(original)); - new_task.flush(); - add = subprocess.Popen(['task', 'rc.verbose=nothing', 'import', new_task.name], env=env) - add.communicate(); + # Wait for taskwarrior to finish, so we can safely `task import` the new task + sys.stdout.flush() + task_pid = os.getppid() + if (0 < os.fork()): + sys.exit(0) + else: + # Taskwarrior also waits for stdout to close + try: + os.close(sys.stdout.fileno()) + except OSError: + pass # Thrown because of closing stdout. Don't worry, that's fine. + + # Wait for taskwarrior to finish + while (os.path.exists("/proc/%s" % str(task_pid))): + time.sleep(0.25) + + # Import the follow-up task + with tempfile.NamedTemporaryFile(mode="wt") as new_task: + new_task.write(json.dumps(original)); + new_task.flush(); + add = subprocess.Popen(['task', 'rc.verbose=nothing', 'import', new_task.name], env=env) + add.communicate(); From a1b6003c4b9322d202cb3e598f2e8b6b2cc2a419 Mon Sep 17 00:00:00 2001 From: Fongshway <8451964+Fongshway@users.noreply.github.com> Date: Mon, 25 May 2020 13:22:30 -0700 Subject: [PATCH 2/3] fix spacing --- on-modify.relative-recur | 80 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/on-modify.relative-recur b/on-modify.relative-recur index b0edebd..6b87db8 100755 --- a/on-modify.relative-recur +++ b/on-modify.relative-recur @@ -22,10 +22,10 @@ env['TZ'] = 'UTC0' # Hand back duration format parsing to task warrior def calc(statement): - calc = subprocess.Popen(['task', 'rc.verbose=nothing', 'rc.date.iso=yes', 'calc', statement], stdout=subprocess.PIPE, env=env) - out, err = calc.communicate() - # Workaround for TW-1254 (https://bug.tasktools.org/browse/TW-1254) - return out.decode("utf-8").rstrip().replace('-', '').replace(':', '') + 'Z' + calc = subprocess.Popen(['task', 'rc.verbose=nothing', 'rc.date.iso=yes', 'calc', statement], stdout=subprocess.PIPE, env=env) + out, err = calc.communicate() + # Workaround for TW-1254 (https://bug.tasktools.org/browse/TW-1254) + return out.decode("utf-8").rstrip().replace('-', '').replace(':', '') + 'Z' # Parse the modified task original = json.loads(sys.stdin.readline()) @@ -36,44 +36,44 @@ modified = json.loads(modified) # Has a task with UDA been marked as completed? if (UDA_DUE in original or UDA_WAIT in original) and original['status']!='completed' and modified['status']=='completed': - del original['modified'] + del original['modified'] - if 'totalactivetime' in original: - del original['totalactivetime'] - if 'start' in original: - del original['start'] - if UDA_DUE in original: - original['due'] = calc(modified['end'] + '+' + original[UDA_DUE]) - if UDA_WAIT in original: - original['wait'] = calc(modified['end'] + '+' + original[UDA_WAIT]) - original['scheduled'] = calc(modified['end'] + '+' + original[UDA_WAIT]) - original['status'] = 'waiting' + if 'totalactivetime' in original: + del original['totalactivetime'] + if 'start' in original: + del original['start'] + if UDA_DUE in original: + original['due'] = calc(modified['end'] + '+' + original[UDA_DUE]) + if UDA_WAIT in original: + original['wait'] = calc(modified['end'] + '+' + original[UDA_WAIT]) + original['scheduled'] = calc(modified['end'] + '+' + original[UDA_WAIT]) + original['status'] = 'waiting' - else: - original['status'] = 'pending' - print('Created follow-up task') - original['entry'] = modified['end'] - original['uuid'] = str(uuid.uuid4()) + else: + original['status'] = 'pending' + print('Created follow-up task') + original['entry'] = modified['end'] + original['uuid'] = str(uuid.uuid4()) - # Wait for taskwarrior to finish, so we can safely `task import` the new task - sys.stdout.flush() - task_pid = os.getppid() - if (0 < os.fork()): - sys.exit(0) - else: - # Taskwarrior also waits for stdout to close - try: - os.close(sys.stdout.fileno()) - except OSError: - pass # Thrown because of closing stdout. Don't worry, that's fine. + # Wait for taskwarrior to finish, so we can safely `task import` the new task + sys.stdout.flush() + task_pid = os.getppid() + if (0 < os.fork()): + sys.exit(0) + else: + # Taskwarrior also waits for stdout to close + try: + os.close(sys.stdout.fileno()) + except OSError: + pass # Thrown because of closing stdout. Don't worry, that's fine. - # Wait for taskwarrior to finish - while (os.path.exists("/proc/%s" % str(task_pid))): - time.sleep(0.25) + # Wait for taskwarrior to finish + while (os.path.exists("/proc/%s" % str(task_pid))): + time.sleep(0.25) - # Import the follow-up task - with tempfile.NamedTemporaryFile(mode="wt") as new_task: - new_task.write(json.dumps(original)); - new_task.flush(); - add = subprocess.Popen(['task', 'rc.verbose=nothing', 'import', new_task.name], env=env) - add.communicate(); + # Import the follow-up task + with tempfile.NamedTemporaryFile(mode="wt") as new_task: + new_task.write(json.dumps(original)); + new_task.flush(); + add = subprocess.Popen(['task', 'rc.verbose=nothing', 'import', new_task.name], env=env) + add.communicate(); From a133ebaccffd0a3c8446bb9a0ec8d06133c42883 Mon Sep 17 00:00:00 2001 From: Fongshway <8451964+Fongshway@users.noreply.github.com> Date: Mon, 25 May 2020 15:46:41 -0700 Subject: [PATCH 3/3] Update on-modify.relative-recur Co-authored-by: Jens Erat --- on-modify.relative-recur | 1 + 1 file changed, 1 insertion(+) diff --git a/on-modify.relative-recur b/on-modify.relative-recur index 6b87db8..df3a0c4 100755 --- a/on-modify.relative-recur +++ b/on-modify.relative-recur @@ -38,6 +38,7 @@ modified = json.loads(modified) if (UDA_DUE in original or UDA_WAIT in original) and original['status']!='completed' and modified['status']=='completed': del original['modified'] + # have follow-up task be created without active time created by time tracking hook https://github.com/kostajh/taskwarrior-time-tracking-hook if 'totalactivetime' in original: del original['totalactivetime'] if 'start' in original: