Addressed review comments

This commit is contained in:
Andrew Katz 2020-07-24 15:35:58 -04:00
parent 5b8b043a70
commit 6b3a89edeb
3 changed files with 12 additions and 6 deletions

View File

@ -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('<!DOCTYPE html>\n')

View File

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

View File

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