diff --git a/ext/on-modify.timewarrior b/ext/on-modify.timewarrior index 6ca0b08d..0e7500c9 100644 --- a/ext/on-modify.timewarrior +++ b/ext/on-modify.timewarrior @@ -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))) diff --git a/test/test_on-modify.timewarrior.t.py b/test/test_on-modify.timewarrior.t.py index 93e5d630..4eda9a18 100755 --- a/test/test_on-modify.timewarrior.t.py +++ b/test/test_on-modify.timewarrior.t.py @@ -120,10 +120,8 @@ class TestOnModifyHookScript(TestCase): """) self.assertRegexpMatches(out, """\ -Tracking foo - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Current (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} +Removed dummy from @1 +Added foo to @1 \{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "foo"\} """) self.assertEqual('', err) @@ -138,14 +136,8 @@ Tracking foo """) self.assertRegexpMatches(out, """\ -Recorded dummy tag1 tag2 - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Ended (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} -Tracking dummy tag3 tag4 - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Current (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} +Removed dummy tag1 tag2 from @1 +Added dummy tag3 tag4 to @1 \{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "tags": \["tag3", "tag4"\], "modified": "20180317T092629Z", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\} """) self.assertEqual('', err) @@ -160,14 +152,8 @@ Tracking dummy tag3 tag4 """) self.assertRegexpMatches(out, """\ -Recorded dummy proj1 - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Ended (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} -Tracking dummy proj2 - Started \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2} - Current (\d{2}:| )\d{2} - Total ?\d{1,2}:\d{2}:\d{2} +Removed dummy proj1 from @1 +Added dummy proj2 to @1 \{"status": "pending", "uuid": "3422d76c-c087-4ecd-9c62-1246b078e534", "modified": "20180317T092629Z", "project": "proj2", "start": "20180317T092629Z", "entry": "20180317T092629Z", "description": "dummy"\} """) self.assertEqual('', err)