mirror of
https://github.com/GothenburgBitFactory/task-timewarrior-hook.git
synced 2025-09-05 23:17:21 +02:00
Handling modifications to description/tag/project for task
The taskwarrior extension script `on-modify.timewarrior` did not forward modifications for description/tag/project to `timew`. This resulted in non-existent tasks (with old tag etc) contiued to be tracked and not updated [Closes #105](https://github.com/GothenburgBitFactory/timewarrior/issues/105)
This commit is contained in:
parent
18eb53bc4a
commit
7f10219760
1 changed files with 25 additions and 10 deletions
|
@ -42,6 +42,18 @@ old = json.loads(sys.stdin.readline())
|
||||||
new = json.loads(sys.stdin.readline())
|
new = json.loads(sys.stdin.readline())
|
||||||
print(json.dumps(new))
|
print(json.dumps(new))
|
||||||
|
|
||||||
|
def get_timew_name_from_json(json_obj):
|
||||||
|
# Extract attributes for use as tags.
|
||||||
|
tags = [json_obj['description']]
|
||||||
|
|
||||||
|
if 'project' in json_obj:
|
||||||
|
tags.append(json_obj['project'])
|
||||||
|
|
||||||
|
if 'tags' in json_obj:
|
||||||
|
tags.extend(json_obj['tags'])
|
||||||
|
|
||||||
|
return ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
|
||||||
|
|
||||||
start_or_stop = ''
|
start_or_stop = ''
|
||||||
|
|
||||||
# Started task.
|
# Started task.
|
||||||
|
@ -53,16 +65,19 @@ elif 'start' not in new and 'start' in old:
|
||||||
start_or_stop = 'stop'
|
start_or_stop = 'stop'
|
||||||
|
|
||||||
if start_or_stop:
|
if start_or_stop:
|
||||||
# Extract attributes for use as tags.
|
combined = get_timew_name_from_json(new)
|
||||||
tags = [new['description']]
|
|
||||||
|
|
||||||
if 'project' in new:
|
|
||||||
tags.append(new['project'])
|
|
||||||
|
|
||||||
if 'tags' in new:
|
|
||||||
tags.extend(new['tags'])
|
|
||||||
|
|
||||||
combined = ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
|
|
||||||
|
|
||||||
command = 'timew {0} {1} :yes'.format(start_or_stop, combined)
|
command = 'timew {0} {1} :yes'.format(start_or_stop, combined)
|
||||||
subprocess.call(shlex.split(command))
|
subprocess.call(shlex.split(command))
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue