Add option to not log completed tasks
This commit is contained in:
parent
26cb264179
commit
73c8c76d3c
1 changed files with 24 additions and 11 deletions
|
@ -17,8 +17,26 @@ parser = argparse.ArgumentParser()
|
|||
parser.add_argument(
|
||||
"-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()
|
||||
|
||||
# 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):
|
||||
curdate = "1970-01-01"
|
||||
|
@ -43,8 +61,8 @@ def extract_tw_data(fname):
|
|||
continue
|
||||
|
||||
completed_task = re.search(r"^x ((?:\([A-D]\))? ?.*)$", line)
|
||||
if completed_task:
|
||||
log_to_taskwarrior(completed_task[1], curdate)
|
||||
if completed_task and is_logging_done_to_tw():
|
||||
log_done_to_taskwarrior(completed_task[1], curdate)
|
||||
lines_to_delete.append(line_number)
|
||||
|
||||
if lines_to_delete:
|
||||
|
@ -65,7 +83,7 @@ def get_prio_string(task_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"
|
||||
|
||||
cmd = [
|
||||
|
@ -78,7 +96,7 @@ def log_to_taskwarrior(task_string, date):
|
|||
get_prio_string(task_string),
|
||||
]
|
||||
|
||||
if is_dryrun:
|
||||
if is_dryrun():
|
||||
print(cmd)
|
||||
return
|
||||
|
||||
|
@ -86,7 +104,8 @@ def log_to_taskwarrior(task_string, date):
|
|||
|
||||
|
||||
def delete_logged_tasks_from_file(fname, lines):
|
||||
if is_dryrun:
|
||||
if is_dryrun():
|
||||
print(f"deleting lines: {lines}")
|
||||
return
|
||||
|
||||
cur_line = 0
|
||||
|
@ -101,12 +120,6 @@ def delete_logged_tasks_from_file(fname, lines):
|
|||
os.rename(repl_file, fname)
|
||||
|
||||
|
||||
def is_dryrun():
|
||||
if args.dryrun:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
extract_tw_data(TODOTXT_FILE)
|
||||
sys.exit(0)
|
||||
|
||||
|
|
Loading…
Reference in a new issue