aboutsummaryrefslogtreecommitdiffstats
path: root/hm/soispha/conf/taskwarrior/hooks/scripts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xhm/soispha/conf/taskwarrior/hooks/scripts/on-modify_track-timewarrior.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_track-timewarrior.py b/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_track-timewarrior.py
index 63065754..03b4ce42 100755
--- a/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_track-timewarrior.py
+++ b/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_track-timewarrior.py
@@ -32,15 +32,27 @@ This hook is a fork from the `official on-modify.timewarrior hook`_.
https://github.com/GothenburgBitFactory/timewarrior/blob/dev/ext/on-modify.timewarrior
"""
-from sys import stdin
-from os import system
+import subprocess
+import sys
from json import loads, dumps
+from os import system
+from sys import stdin
+from taskw import TaskWarrior
# Make no changes to the task, simply observe.
old = loads(stdin.readline())
new = loads(stdin.readline())
print(dumps(new))
+
+w = TaskWarrior(config_filename=sys.argv[4].replace("rc:", ""))
+config = w.load_config(config_filename=sys.argv[4].replace("rc:", ""))
+if "max_active_tasks" in config:
+ MAX_ACTIVE = int(config["max_active_tasks"])
+else:
+ MAX_ACTIVE = 1
+
+
# Extract attributes for use as tags.
tags = [new["description"]]
@@ -57,6 +69,15 @@ combined = " ".join(["'%s'" % tag for tag in tags]).encode("utf-8").strip()
# Task has been started.
if "start" in new and not "start" in old:
+ # Prevent this task from starting if "task +ACTIVE count" is greater than "MAX_ACTIVE".
+ p = subprocess.Popen(["task", "+ACTIVE", "status:pending", "count", "rc.verbose:off"], stdout=subprocess.PIPE)
+ out, err = p.communicate()
+ count = int(out.rstrip())
+ if count >= MAX_ACTIVE:
+ print("Only %d task(s) can be active at a time. "
+ "See 'max_active_tasks' in .taskrc." % MAX_ACTIVE)
+ sys.exit(1)
+
system("timew start " + combined.decode() + " :yes")
# Task has been stopped.