Add option to add incomplete tasks to taskwarrior
This commit is contained in:
parent
30c6aea11b
commit
fcf3b791b4
2 changed files with 70 additions and 27 deletions
|
@ -48,8 +48,11 @@ def process_file(options):
|
||||||
if handle_completed_tasks(line, curdate, options):
|
if handle_completed_tasks(line, curdate, options):
|
||||||
lines_to_delete.append(line_number)
|
lines_to_delete.append(line_number)
|
||||||
|
|
||||||
|
if handle_open_tasks(line, curdate, options):
|
||||||
|
lines_to_delete.append(line_number)
|
||||||
|
|
||||||
if lines_to_delete:
|
if lines_to_delete:
|
||||||
delete_logged_tasks_from_file(fname, lines_to_delete, options.dryrun)
|
delete_lines_from_file(fname, lines_to_delete, options.dryrun)
|
||||||
|
|
||||||
|
|
||||||
def handle_completed_tasks(line, date, options):
|
def handle_completed_tasks(line, date, options):
|
||||||
|
@ -63,20 +66,6 @@ def handle_completed_tasks(line, date, options):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_prio_string(task_string):
|
|
||||||
prio = re.search(r"^\(([ABC])\) (.*)$", task_string)
|
|
||||||
prio_string = ""
|
|
||||||
if prio:
|
|
||||||
task_string = prio[2]
|
|
||||||
if prio[1] == "A":
|
|
||||||
prio_string = "prio:H"
|
|
||||||
elif prio[1] == "B":
|
|
||||||
prio_string = "prio:M"
|
|
||||||
elif prio[1] == "C":
|
|
||||||
prio_string = "prio:L"
|
|
||||||
return prio_string
|
|
||||||
|
|
||||||
|
|
||||||
def log_completed_to_taskwarrior(task_string, date, options):
|
def log_completed_to_taskwarrior(task_string, date, options):
|
||||||
overrides = options.taskwarrior_overrides
|
overrides = options.taskwarrior_overrides
|
||||||
cmd = [
|
cmd = [
|
||||||
|
@ -94,7 +83,49 @@ def log_completed_to_taskwarrior(task_string, date, options):
|
||||||
subprocess.Popen(cmd)
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
|
|
||||||
def delete_logged_tasks_from_file(fname, lines, dryrun):
|
def handle_open_tasks(line, date, options):
|
||||||
|
completed_task = re.search(
|
||||||
|
rf"^{options.regex_task_incomplete} ((?:\([A-D]\))? ?.*)$",
|
||||||
|
line,
|
||||||
|
)
|
||||||
|
if completed_task and options.taskwarrior_add_incomplete:
|
||||||
|
add_incomplete_to_taskwarrior(completed_task[1], date, options)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def add_incomplete_to_taskwarrior(task_string, date, options):
|
||||||
|
overrides = options.taskwarrior_overrides
|
||||||
|
cmd = [
|
||||||
|
"task",
|
||||||
|
*overrides,
|
||||||
|
"add",
|
||||||
|
f'"{task_string}"',
|
||||||
|
f"entry:{date}",
|
||||||
|
f"scheduled:{date}",
|
||||||
|
get_prio_string(task_string),
|
||||||
|
]
|
||||||
|
if options.dryrun:
|
||||||
|
print(cmd)
|
||||||
|
return
|
||||||
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def get_prio_string(task_string):
|
||||||
|
prio = re.search(r"^\(([ABC])\) (.*)$", task_string)
|
||||||
|
prio_string = ""
|
||||||
|
if prio:
|
||||||
|
task_string = prio[2]
|
||||||
|
if prio[1] == "A":
|
||||||
|
prio_string = "prio:H"
|
||||||
|
elif prio[1] == "B":
|
||||||
|
prio_string = "prio:M"
|
||||||
|
elif prio[1] == "C":
|
||||||
|
prio_string = "prio:L"
|
||||||
|
return prio_string
|
||||||
|
|
||||||
|
|
||||||
|
def delete_lines_from_file(fname, lines, dryrun):
|
||||||
if dryrun:
|
if dryrun:
|
||||||
print(f"deleting lines: {lines}")
|
print(f"deleting lines: {lines}")
|
||||||
return
|
return
|
||||||
|
|
34
options.py
34
options.py
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -10,25 +11,28 @@ class Options:
|
||||||
todo_block_title: str = "todotxt"
|
todo_block_title: str = "todotxt"
|
||||||
dryrun: bool = False
|
dryrun: bool = False
|
||||||
taskwarrior_log_completed: bool = True
|
taskwarrior_log_completed: bool = True
|
||||||
|
taskwarrior_add_incomplete: bool = True
|
||||||
|
|
||||||
# can not yet be changed
|
# can not yet be changed
|
||||||
taskwarrior_overrides: list = [
|
taskwarrior_overrides: List = field(
|
||||||
"rc.context=none",
|
default_factory=lambda: [
|
||||||
"rc.verbose=nothing",
|
"rc.context=none",
|
||||||
"rc.hooks=0",
|
"rc.verbose=nothing",
|
||||||
]
|
"rc.hooks=0",
|
||||||
regex_task_completed: str = r"(?:x|[x])"
|
]
|
||||||
regex_task_incomplete: str = r"[ ]"
|
)
|
||||||
|
regex_task_completed: str = r"(?:x|\[x\])"
|
||||||
|
regex_task_incomplete: str = r"\[ \]"
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
opt = Options()
|
opt = Options()
|
||||||
parse_cmdline_args(opt)
|
parse_cmdline_args(opt)
|
||||||
print_dryrun(opt)
|
dryrun_show_options(opt)
|
||||||
return opt
|
return opt
|
||||||
|
|
||||||
|
|
||||||
def print_dryrun(options):
|
def dryrun_show_options(options):
|
||||||
print(options)
|
print(options)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,12 +49,20 @@ def parse_cmdline_args(options):
|
||||||
help="don't log done todo items to taskwarrior",
|
help="don't log done todo items to taskwarrior",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-I",
|
||||||
|
"--noincomplete",
|
||||||
|
help="don't add incomplete todo items to taskwarrior",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.dryrun:
|
if args.dryrun:
|
||||||
options.dryrun = True
|
options.dryrun = True
|
||||||
if args.nologging:
|
if args.nologging:
|
||||||
options.taskwarrior_log_done = False
|
options.taskwarrior_log_completed = False
|
||||||
|
if args.noincomplete:
|
||||||
|
options.taskwarrior_add_incomplete = False
|
||||||
if args.file:
|
if args.file:
|
||||||
options.jrnl_fname = args.file
|
options.jrnl_fname = args.file
|
||||||
if args.blocktitle:
|
if args.blocktitle:
|
||||||
|
|
Loading…
Reference in a new issue