mirror of
https://github.com/GothenburgBitFactory/task-timewarrior-hook.git
synced 2025-06-26 10:54:27 +02:00
ReviewFixes: Reset tags instead of stop/start task; formatting changes
This commit is contained in:
parent
7f10219760
commit
0a08541161
1 changed files with 8 additions and 12 deletions
|
@ -42,7 +42,7 @@ old = json.loads(sys.stdin.readline())
|
|||
new = json.loads(sys.stdin.readline())
|
||||
print(json.dumps(new))
|
||||
|
||||
def get_timew_name_from_json(json_obj):
|
||||
def extract_timew_tags_from(json_obj):
|
||||
# Extract attributes for use as tags.
|
||||
tags = [json_obj['description']]
|
||||
|
||||
|
@ -52,7 +52,7 @@ def get_timew_name_from_json(json_obj):
|
|||
if 'tags' in json_obj:
|
||||
tags.extend(json_obj['tags'])
|
||||
|
||||
return ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
|
||||
return ' '.join(['"{0}"'.format(tag) for tag in tags]).encode('utf-8').strip()
|
||||
|
||||
start_or_stop = ''
|
||||
|
||||
|
@ -65,19 +65,15 @@ elif 'start' not in new and 'start' in old:
|
|||
start_or_stop = 'stop'
|
||||
|
||||
if start_or_stop:
|
||||
combined = get_timew_name_from_json(new)
|
||||
combined = extract_timew_tags_from(new)
|
||||
|
||||
command = 'timew {0} {1} :yes'.format(start_or_stop, combined)
|
||||
subprocess.call(shlex.split(command))
|
||||
subprocess.call(shlex.split('timew {0} {1} :yes'.format(start_or_stop, combined)))
|
||||
|
||||
# Modifications to task other than start/stop
|
||||
elif 'start' in new and 'start' in old:
|
||||
old_combined = get_timew_name_from_json(old)
|
||||
new_combined = get_timew_name_from_json(new)
|
||||
old_combined = extract_timew_tags_from(old)
|
||||
new_combined = extract_timew_tags_from(new)
|
||||
|
||||
if old_combined != new_combined:
|
||||
command = 'timew stop {0} :yes'.format(old_combined)
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
command = 'timew start {0} :yes'.format(new_combined)
|
||||
subprocess.call(shlex.split(command))
|
||||
subprocess.call(shlex.split('timew untag @1 {0} :yes'.format(old_combined)))
|
||||
subprocess.call(shlex.split('timew tag @1 {0} :yes'.format(new_combined)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue