mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Update on-modify.timewarrior to 360fc2292a5eab46cd5c9bdd4cc791b6f9ea5e9a
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
123632a806
commit
edfabcc1e5
1 changed files with 32 additions and 30 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
###############################################################################
|
||||
#
|
||||
# Copyright 2016 - 2021, Thomas Lauf, Paul Beckingham, Federico Hernandez.
|
||||
# Copyright 2016 - 2021, 2023, Gothenburg Bit Factory
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -26,13 +26,11 @@
|
|||
#
|
||||
###############################################################################
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Hook should extract all of the following for use as Timewarrior tags:
|
||||
# Hook should extract all the following for use as Timewarrior tags:
|
||||
# UUID
|
||||
# Project
|
||||
# Tags
|
||||
|
@ -44,11 +42,6 @@ try:
|
|||
except AttributeError:
|
||||
input_stream = sys.stdin
|
||||
|
||||
# Make no changes to the task, simply observe.
|
||||
old = json.loads(input_stream.readline().decode("utf-8", errors="replace"))
|
||||
new = json.loads(input_stream.readline().decode("utf-8", errors="replace"))
|
||||
print(json.dumps(new))
|
||||
|
||||
|
||||
def extract_tags_from(json_obj):
|
||||
# Extract attributes for use as tags.
|
||||
|
@ -71,32 +64,41 @@ def extract_annotation_from(json_obj):
|
|||
return json_obj['annotations'][0]['description']
|
||||
|
||||
|
||||
start_or_stop = ''
|
||||
def main(old, new):
|
||||
|
||||
# Started task.
|
||||
if 'start' in new and 'start' not in old:
|
||||
start_or_stop = 'start'
|
||||
start_or_stop = ''
|
||||
|
||||
# Stopped task.
|
||||
elif ('start' not in new or 'end' in new) and 'start' in old:
|
||||
start_or_stop = 'stop'
|
||||
# Started task.
|
||||
if 'start' in new and 'start' not in old:
|
||||
start_or_stop = 'start'
|
||||
|
||||
if start_or_stop:
|
||||
tags = extract_tags_from(new)
|
||||
# Stopped task.
|
||||
elif ('start' not in new or 'end' in new) and 'start' in old:
|
||||
start_or_stop = 'stop'
|
||||
|
||||
subprocess.call(['timew', start_or_stop] + tags + [':yes'])
|
||||
if start_or_stop:
|
||||
tags = extract_tags_from(new)
|
||||
|
||||
# Modifications to task other than start/stop
|
||||
elif 'start' in new and 'start' in old:
|
||||
old_tags = extract_tags_from(old)
|
||||
new_tags = extract_tags_from(new)
|
||||
subprocess.call(['timew', start_or_stop] + tags + [':yes'])
|
||||
|
||||
if old_tags != new_tags:
|
||||
subprocess.call(['timew', 'untag', '@1'] + old_tags + [':yes'])
|
||||
subprocess.call(['timew', 'tag', '@1'] + new_tags + [':yes'])
|
||||
# Modifications to task other than start/stop
|
||||
elif 'start' in new and 'start' in old:
|
||||
old_tags = extract_tags_from(old)
|
||||
new_tags = extract_tags_from(new)
|
||||
|
||||
old_annotation = extract_annotation_from(old)
|
||||
new_annotation = extract_annotation_from(new)
|
||||
if old_tags != new_tags:
|
||||
subprocess.call(['timew', 'untag', '@1'] + old_tags + [':yes'])
|
||||
subprocess.call(['timew', 'tag', '@1'] + new_tags + [':yes'])
|
||||
|
||||
if old_annotation != new_annotation:
|
||||
subprocess.call(['timew', 'annotate', '@1', new_annotation])
|
||||
old_annotation = extract_annotation_from(old)
|
||||
new_annotation = extract_annotation_from(new)
|
||||
|
||||
if old_annotation != new_annotation:
|
||||
subprocess.call(['timew', 'annotate', '@1', new_annotation])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
old = json.loads(input_stream.readline().decode("utf-8", errors="replace"))
|
||||
new = json.loads(input_stream.readline().decode("utf-8", errors="replace"))
|
||||
print(json.dumps(new))
|
||||
main(old, new)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue