diff --git a/.task/backlog.data b/.task/backlog.data index e0c316c..c6c96d2 100644 --- a/.task/backlog.data +++ b/.task/backlog.data @@ -54,3 +54,5 @@ {"description":"config: handle config files from taskwarrior first","end":"20230819T190559Z","entry":"20230811T171231Z","modified":"20230819T190559Z","status":"completed","uuid":"4d822c4a-d51e-4992-8a22-6e0167ac197a","tags":["feat"]} {"description":"screenshots: to be added to the README on Github.","entry":"20230820T133634Z","modified":"20230820T133634Z","status":"pending","uuid":"b5f1d2b6-9e2f-458f-afab-880c52121c82","tags":["website"]} {"description":"screenshots: to be added to the README on Github.","entry":"20230820T133634Z","modified":"20230820T133640Z","start":"20230820T133640Z","status":"pending","uuid":"b5f1d2b6-9e2f-458f-afab-880c52121c82","tags":["website"]} +{"description":"screenshots: to be added to the README on Github.","end":"20230820T154052Z","entry":"20230820T133634Z","modified":"20230820T154052Z","status":"completed","uuid":"b5f1d2b6-9e2f-458f-afab-880c52121c82","tags":["website"]} +{"description":"find data updir: try to find .task on upper directories if not in the existing one","entry":"20230811T170621Z","modified":"20230820T162832Z","priority":"H","start":"20230820T162832Z","status":"pending","uuid":"b4ee0b55-0bb3-4a2f-b7c5-87cd70dd0ff0","tags":["data","feat"]} diff --git a/.task/completed.data b/.task/completed.data index c929e6e..7e8eb61 100644 --- a/.task/completed.data +++ b/.task/completed.data @@ -1,3 +1,4 @@ +[description:"screenshots: to be added to the README on Github." end:"1692546052" entry:"1692538594" modified:"1692546052" status:"completed" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] [description:"config: handle config files from taskwarrior first" end:"1692471959" entry:"1691773951" modified:"1692471959" status:"completed" tags:"feat" tags_feat:"x" uuid:"4d822c4a-d51e-4992-8a22-6e0167ac197a"] [description:"sort by urgency" end:"1692214597" entry:"1691773782" modified:"1692214597" priority:"H" status:"completed" tags:"feat" tags_feat:"x" uuid:"4f041f52-739a-4aca-94e6-164f43e61866"] [description:"sorting: allow sorting within a stacker." end:"1692214508" entry:"1692187030" modified:"1692214508" status:"completed" tags:"feat" tags_feat:"x" uuid:"30ec6b32-a32e-4595-a24d-02ac9002fd72"] diff --git a/.task/pending.data b/.task/pending.data index 43defa1..b572f67 100644 --- a/.task/pending.data +++ b/.task/pending.data @@ -1,4 +1,4 @@ -[description:"find data updir: try to find .task on upper directories if not in the existing one" entry:"1691773581" modified:"1692121517" priority:"H" status:"pending" tags:"data,feat" tags_data:"x" tags_feat:"x" uuid:"b4ee0b55-0bb3-4a2f-b7c5-87cd70dd0ff0"] +[description:"find data updir: try to find .task on upper directories if not in the existing one" entry:"1691773581" modified:"1692548912" priority:"H" start:"1692548912" status:"pending" tags:"data,feat" tags_data:"x" tags_feat:"x" uuid:"b4ee0b55-0bb3-4a2f-b7c5-87cd70dd0ff0"] [description:"semantic tags : allow tags starting with a hash to refer to a github issue or PR" entry:"1691773642" modified:"1692121563" priority:"L" status:"pending" tags:"feat" tags_feat:"x" uuid:"06cf70a9-4f0e-4b32-b7bb-d1799803665c"] [description:"hide old done tasks: Hide tasks with last status that haven t been touched since a long time." entry:"1691773751" modified:"1692122496" priority:"M" status:"pending" tags:"feat" tags_feat:"x" uuid:"e18707b4-304d-41f3-8504-89476cd796f5"] [description:"fix escaped add: when passing add with escapable characters, bug ensues." entry:"1691774077" modified:"1691774077" status:"pending" tags:"bug" tags_bug:"x" uuid:"79e1ba11-15ae-489f-9868-ab6adea40a91"] @@ -8,4 +8,3 @@ [description:"handle prompts: for some commands like delete, taskwarrior setup an interactive prompt, which needs to be handled." entry:"1692122614" modified:"1692122614" status:"pending" tags:"bug" tags_bug:"x" uuid:"e2480c4b-4c73-4d03-8568-82f14ade7b38"] [description:"semantic colors: allow coloring by values, not just fields." entry:"1692255328" modified:"1692255328" status:"pending" tags:"feat,themes" tags_feat:"x" tags_themes:"x" uuid:"1a5aab4a-0c2b-444f-9259-6eddc29b9791"] [description:"theme config: use taskwarrior theme config and extends from there." entry:"1692471868" modified:"1692471868" status:"pending" tags:"feat,themes" tags_feat:"x" tags_themes:"x" uuid:"6b248843-1b11-487b-85e8-a96e668f6772"] -[description:"screenshots: to be added to the README on Github." entry:"1692538594" modified:"1692538600" start:"1692538600" status:"pending" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] diff --git a/.task/undo.data b/.task/undo.data index 0ee0f9d..23c0270 100644 --- a/.task/undo.data +++ b/.task/undo.data @@ -197,3 +197,11 @@ time 1692538600 old [description:"screenshots: to be added to the README on Github." entry:"1692538594" modified:"1692538594" status:"pending" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] new [description:"screenshots: to be added to the README on Github." entry:"1692538594" modified:"1692538600" start:"1692538600" status:"pending" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] --- +time 1692546052 +old [description:"screenshots: to be added to the README on Github." entry:"1692538594" modified:"1692538600" start:"1692538600" status:"pending" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] +new [description:"screenshots: to be added to the README on Github." end:"1692546052" entry:"1692538594" modified:"1692546052" status:"completed" tags:"website" tags_website:"x" uuid:"b5f1d2b6-9e2f-458f-afab-880c52121c82"] +--- +time 1692548912 +old [description:"find data updir: try to find .task on upper directories if not in the existing one" entry:"1691773581" modified:"1692121517" priority:"H" status:"pending" tags:"data,feat" tags_data:"x" tags_feat:"x" uuid:"b4ee0b55-0bb3-4a2f-b7c5-87cd70dd0ff0"] +new [description:"find data updir: try to find .task on upper directories if not in the existing one" entry:"1691773581" modified:"1692548912" priority:"H" start:"1692548912" status:"pending" tags:"data,feat" tags_data:"x" tags_feat:"x" uuid:"b4ee0b55-0bb3-4a2f-b7c5-87cd70dd0ff0"] +--- diff --git a/taskwarrior-deluxe.py b/taskwarrior-deluxe.py index 3849ca6..f674864 100755 --- a/taskwarrior-deluxe.py +++ b/taskwarrior-deluxe.py @@ -4,7 +4,8 @@ import os import re import sys import json -import argparse +import queue +import pathlib import textwrap import subprocess @@ -561,8 +562,8 @@ def get_layouts(kind = None, name = None): # We cannot use tomllib because strings are not quoted. # We cannot use configparser because there is no section and because of the 'include' command. # FIXME handle possible values when possible. -def parse_config(filename, default): - config = default +def parse_config(filename, current): + config = current with open(filename, 'r') as fd: for i,line in enumerate(fd.readlines()): if line.strip() and line.strip()[0] != '#': @@ -588,6 +589,49 @@ def as_bool(s): raise ValueError(f"Cannot interpret `{s}` as a boolean.") +def upsearch(filename, at = pathlib.Path.cwd()): + current = at + root = pathlib.Path(current.root) + + while current != root: + found = current / filename + if found.exists(): + return found + current = current.parent + + return None + + +def load_configs(fname, current): + config = current + + # First, system. + p = pathlib.Path("/etc/taskwarrior") / pathlib.Path(fname) + if p.exists(): + config = parse_config(p, config) + + # Second, user. + p = pathlib.Path(os.path.expanduser('~')) / pathlib.Path(fname) + if p.exists(): + config = parse_config(p, config) + + # Third, upper dirs. + # LIFO queue allows to fill from current dir, + # then read from upper dir. + updirs = queue.LifoQueue() + here = pathlib.Path.cwd() + f = upsearch(fname, here) + while f: + updirs.put(f) + f = upsearch(fname, f.parent.parent) + + while not updirs.empty(): + f = updirs.get() + config = parse_config(f, config) + + return config + + if __name__ == "__main__": default_conf = { @@ -608,9 +652,10 @@ if __name__ == "__main__": "widget.card.wrap": "25", } - # TODO seek files up dans in config paths. - config_tw = parse_config(os.path.expanduser('~/.taskrc'), default_conf) - config = parse_config(os.path.expanduser('~/.twdrc'), config_tw) + # First, taskwarrior's config... + config = load_configs(".taskrc", default_conf) + # ... overwritten by TWD config. + config = load_configs(".twdrc", config) # for k in config: # print(k,"=",config[k])