Add option to not log completed tasks

This commit is contained in:
Marty Oehme 2021-10-31 11:40:36 +01:00
parent 26cb264179
commit 73c8c76d3c
Signed by: Marty
GPG key ID: B7538B8F50A1C800

View file

@ -17,8 +17,26 @@ parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"-n", "--dryrun", help="only simulate and print changes", action="store_true" "-n", "--dryrun", help="only simulate and print changes", action="store_true"
) )
parser.add_argument(
"-L",
"--nologging",
help="don't log done todo items to taskwarrior",
action="store_true",
)
args = parser.parse_args() args = parser.parse_args()
# set options
def is_dryrun():
if args.dryrun:
return True
return False
def is_logging_done_to_tw():
if args.nologging:
return False
return True
def extract_tw_data(fname): def extract_tw_data(fname):
curdate = "1970-01-01" curdate = "1970-01-01"
@ -43,8 +61,8 @@ def extract_tw_data(fname):
continue continue
completed_task = re.search(r"^x ((?:\([A-D]\))? ?.*)$", line) completed_task = re.search(r"^x ((?:\([A-D]\))? ?.*)$", line)
if completed_task: if completed_task and is_logging_done_to_tw():
log_to_taskwarrior(completed_task[1], curdate) log_done_to_taskwarrior(completed_task[1], curdate)
lines_to_delete.append(line_number) lines_to_delete.append(line_number)
if lines_to_delete: if lines_to_delete:
@ -65,7 +83,7 @@ def get_prio_string(task_string):
return prio_string return prio_string
def log_to_taskwarrior(task_string, date): def log_done_to_taskwarrior(task_string, date):
overrides = "rc.context=none rc.hooks=0" overrides = "rc.context=none rc.hooks=0"
cmd = [ cmd = [
@ -78,7 +96,7 @@ def log_to_taskwarrior(task_string, date):
get_prio_string(task_string), get_prio_string(task_string),
] ]
if is_dryrun: if is_dryrun():
print(cmd) print(cmd)
return return
@ -86,7 +104,8 @@ def log_to_taskwarrior(task_string, date):
def delete_logged_tasks_from_file(fname, lines): def delete_logged_tasks_from_file(fname, lines):
if is_dryrun: if is_dryrun():
print(f"deleting lines: {lines}")
return return
cur_line = 0 cur_line = 0
@ -101,12 +120,6 @@ def delete_logged_tasks_from_file(fname, lines):
os.rename(repl_file, fname) os.rename(repl_file, fname)
def is_dryrun():
if args.dryrun:
return True
return False
extract_tw_data(TODOTXT_FILE) extract_tw_data(TODOTXT_FILE)
sys.exit(0) sys.exit(0)