From 6b3a89edebb08271235a6f7703f40c0147589536 Mon Sep 17 00:00:00 2001 From: Andrew Katz Date: Fri, 24 Jul 2020 15:35:58 -0400 Subject: [PATCH] Addressed review comments --- src/wireviz/Harness.py | 2 +- src/wireviz/bom_helper.py | 15 +++++++++++---- src/wireviz/wv_helper.py | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index c0b598b..80d250a 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -298,7 +298,7 @@ class Harness: # bom output bom_list = self.bom_list() # todo: support user choices of BOM format (probably also graphviz outputs, html outputs) - bom_helper.generate_bom_outputs(filename,bom_list,bom_helper.WIREVIZ_TSV, bom_helper.EXCEL_CSV) + bom_helper.generate_bom_outputs(filename,bom_list, [bom_helper.WIREVIZ_TSV, bom_helper.EXCEL_CSV]) # HTML output with open_file_write(f'{filename}.html') as file: file.write('\n') diff --git a/src/wireviz/bom_helper.py b/src/wireviz/bom_helper.py index d1e704f..218b413 100644 --- a/src/wireviz/bom_helper.py +++ b/src/wireviz/bom_helper.py @@ -26,10 +26,17 @@ _tsv_formats = { EXCEL_TSV, WIREVIZ_TSV } _csv_ext = '.bom.csv' _tsv_ext = '.bom.tsv' -def generate_bom_outputs(base_filename, bomdata, *argv): - expanded_csv_names = len(_csv_formats.intersection(set(argv))) > 1 - expanded_tsv_names = len(_tsv_formats.intersection(set(argv))) > 1 - for fmt in argv: +def generate_bom_outputs(base_filename, bomdata, formats=None): + if formats is None: + formats = [EXCEL_CSV, WIREVIZ_TSV] + elif isinstance(formats, csv.Dialect): + formats = [formats] + elif not isinstance(formats, list): + raise TypeError + expanded_csv_names = len(_csv_formats.intersection(set(formats))) > 1 + expanded_tsv_names = len(_tsv_formats.intersection(set(formats))) > 1 + + for fmt in formats: if fmt in _csv_formats: file = csv.writer(open_file_write(base_filename + ("_" + fmt.__name__ if expanded_csv_names else "") + _csv_ext, fmt.lineterminator), fmt) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 17aede0..703eb8c 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -113,7 +113,6 @@ def remove_line_breaks(inp): return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp def open_file_read(filename): - # TODO: Intelligently determine encoding (UnicodeDammit, Chardet, cchardet are not very reliable in testing) return open(filename, 'r', encoding='UTF-8') def open_file_write(filename, newline='\n'):