mirror of
https://github.com/GothenburgBitFactory/task-timewarrior-hook.git
synced 2025-06-26 10:54:27 +02:00
Small refactoring
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
38ddeec03c
commit
cc24ea76fb
1 changed files with 10 additions and 8 deletions
|
@ -48,7 +48,8 @@ old = json.loads(input_stream.readline().decode("utf-8", errors="replace"))
|
||||||
new = 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))
|
print(json.dumps(new))
|
||||||
|
|
||||||
def extract_timew_tags_from(json_obj):
|
|
||||||
|
def extract_tags_from(json_obj):
|
||||||
# Extract attributes for use as tags.
|
# Extract attributes for use as tags.
|
||||||
tags = [json_obj['description']]
|
tags = [json_obj['description']]
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ def extract_timew_tags_from(json_obj):
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
start_or_stop = ''
|
start_or_stop = ''
|
||||||
|
|
||||||
# Started task.
|
# Started task.
|
||||||
|
@ -71,15 +73,15 @@ elif ('start' not in new or 'end' in new) and 'start' in old:
|
||||||
start_or_stop = 'stop'
|
start_or_stop = 'stop'
|
||||||
|
|
||||||
if start_or_stop:
|
if start_or_stop:
|
||||||
combined = extract_timew_tags_from(new)
|
tags = extract_tags_from(new)
|
||||||
|
|
||||||
subprocess.call(['timew', start_or_stop] + combined + [':yes'])
|
subprocess.call(['timew', start_or_stop] + tags + [':yes'])
|
||||||
|
|
||||||
# Modifications to task other than start/stop
|
# Modifications to task other than start/stop
|
||||||
elif 'start' in new and 'start' in old:
|
elif 'start' in new and 'start' in old:
|
||||||
old_combined = extract_timew_tags_from(old)
|
old_tags = extract_tags_from(old)
|
||||||
new_combined = extract_timew_tags_from(new)
|
new_tags = extract_tags_from(new)
|
||||||
|
|
||||||
if old_combined != new_combined:
|
if old_tags != new_tags:
|
||||||
subprocess.call(['timew', 'untag', '@1'] + old_combined + [':yes'])
|
subprocess.call(['timew', 'untag', '@1'] + old_tags + [':yes'])
|
||||||
subprocess.call(['timew', 'tag', '@1'] + new_combined + [':yes'])
|
subprocess.call(['timew', 'tag', '@1'] + new_tags + [':yes'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue