ReviewFixes: Reset tags instead of stop/start task; formatting changes

This commit is contained in:
Harish Ved 2018-05-14 09:55:40 +05:30 committed by Thomas Lauf
parent 7f10219760
commit 0a08541161

View file

@ -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)))