Last active
February 13, 2025 15:29
-
-
Save ideasman42/bbd06fd41d45734463dd40a84cd1a4ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This script wraps taskwarrior, | |
# allowing the tasks to be stored in plain-text. | |
# `taskchampion.sqlite3.dump` can be stored in GIT. | |
# This script creates it on demand. | |
import os | |
import sys | |
import subprocess | |
task_dir = os.path.expanduser("~/.local/task") | |
task_bin = os.path.join(task_dir, "taskchampion.sqlite3") | |
task_txt = os.path.join(task_dir, "taskchampion.sqlite3.dump") | |
task_cmd = "/usr/bin/task" | |
# When running for the first time, the text wont exist. | |
if os.path.exists(task_txt): | |
if os.path.exists(task_bin): | |
os.unlink(task_bin) | |
cmd = ( | |
"sqlite3", | |
task_bin, | |
".read " + task_txt, | |
) | |
subprocess.check_call(cmd) | |
cmd = ( | |
task_cmd, | |
*sys.argv[1:], | |
) | |
subprocess.check_call(cmd) | |
# Unlikely but not impossible, write a new file. | |
if not os.path.exists(task_txt): | |
# Always update. | |
cmd = ( | |
"sqlite3", | |
task_bin, | |
".output " + task_txt, | |
# Annoying, without this, every conversion gets a new entry. | |
"DELETE FROM sqlite_sequence", | |
".dump", | |
) | |
subprocess.check_call(cmd) | |
else: | |
# Only update on file-change. | |
cmd = ( | |
"sqlite3", | |
task_bin, | |
# Edit, while tasks can be read, this seems to corrupt the data | |
# (can read but can't delete items, keep commented). | |
#~ # Annoying, without this, every conversion gets a new entry. | |
#~ "DELETE FROM sqlite_sequence", | |
#~ # These also get added and don't seem to be needed. | |
#~ "DELETE FROM working_set", | |
".dump", | |
) | |
dump_new = subprocess.check_output(cmd) | |
with open(task_txt, "rb") as fh: | |
dump_old = fh.read() | |
if dump_new != dump_old: | |
with open(task_txt, "wb") as fh: | |
fh.write(dump_new) | |
if os.path.exists(task_bin): | |
os.unlink(task_bin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment