From 4ce5c67b346f27601192a9941ebd1d40aa6fc20a Mon Sep 17 00:00:00 2001 From: Chad Cassady Date: Fri, 6 Jan 2017 05:44:01 -0800 Subject: [PATCH 1/2] Only append '.json' to output file name if it is not already present --- wig/classes/output.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wig/classes/output.py b/wig/classes/output.py index 2b3ba13..edd4624 100644 --- a/wig/classes/output.py +++ b/wig/classes/output.py @@ -97,7 +97,8 @@ def add_error(self, msg): def write_file(self): file_name = self.options['write_file'] - with open(file_name+ '.json', 'w') as fh: + file_name = file_name if re.search(r'\.json\s*$', file_name) else file_name + '.json' + with open(file_name, 'w') as fh: fh.write(json.dumps(self.json_data, sort_keys=True, indent=4, separators=(',', ': '))) From 16c86327e9771f2f6dbba8533e75b6b63f5f1f4d Mon Sep 17 00:00:00 2001 From: Chad Cassady Date: Fri, 17 Feb 2017 09:44:16 -0800 Subject: [PATCH 2/2] updated 4ce5c67b346f27601192a9941ebd1d40aa6fc20a to merge lines 99-100 into one per code review --- wig/classes/output.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wig/classes/output.py b/wig/classes/output.py index edd4624..68c12d3 100644 --- a/wig/classes/output.py +++ b/wig/classes/output.py @@ -96,10 +96,9 @@ def add_error(self, msg): }) def write_file(self): - file_name = self.options['write_file'] - file_name = file_name if re.search(r'\.json\s*$', file_name) else file_name + '.json' - with open(file_name, 'w') as fh: - fh.write(json.dumps(self.json_data, sort_keys=True, indent=4, separators=(',', ': '))) + file_name = re.sub('(\.json)?\s*$', '', self.options['write_file']) + '.json' + with open(file_name, 'w') as fh: + fh.write(json.dumps(self.json_data, sort_keys=True, indent=4, separators=(',', ': '))) class OutputPrinter(Output):