Addressed review comments
This commit is contained in:
parent
5b8b043a70
commit
6b3a89edeb
@ -298,7 +298,7 @@ class Harness:
|
|||||||
# bom output
|
# bom output
|
||||||
bom_list = self.bom_list()
|
bom_list = self.bom_list()
|
||||||
# todo: support user choices of BOM format (probably also graphviz outputs, html outputs)
|
# 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
|
# HTML output
|
||||||
with open_file_write(f'{filename}.html') as file:
|
with open_file_write(f'{filename}.html') as file:
|
||||||
file.write('<!DOCTYPE html>\n')
|
file.write('<!DOCTYPE html>\n')
|
||||||
|
|||||||
@ -26,10 +26,17 @@ _tsv_formats = { EXCEL_TSV, WIREVIZ_TSV }
|
|||||||
_csv_ext = '.bom.csv'
|
_csv_ext = '.bom.csv'
|
||||||
_tsv_ext = '.bom.tsv'
|
_tsv_ext = '.bom.tsv'
|
||||||
|
|
||||||
def generate_bom_outputs(base_filename, bomdata, *argv):
|
def generate_bom_outputs(base_filename, bomdata, formats=None):
|
||||||
expanded_csv_names = len(_csv_formats.intersection(set(argv))) > 1
|
if formats is None:
|
||||||
expanded_tsv_names = len(_tsv_formats.intersection(set(argv))) > 1
|
formats = [EXCEL_CSV, WIREVIZ_TSV]
|
||||||
for fmt in argv:
|
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:
|
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)
|
file = csv.writer(open_file_write(base_filename + ("_" + fmt.__name__ if expanded_csv_names else "") + _csv_ext, fmt.lineterminator), fmt)
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,6 @@ def remove_line_breaks(inp):
|
|||||||
return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp
|
return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp
|
||||||
|
|
||||||
def open_file_read(filename):
|
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')
|
return open(filename, 'r', encoding='UTF-8')
|
||||||
|
|
||||||
def open_file_write(filename, newline='\n'):
|
def open_file_write(filename, newline='\n'):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user