From 5197298cafd1a754f705b9ef08a7c14f713976f2 Mon Sep 17 00:00:00 2001 From: "Jason R. Jones" Date: Fri, 24 Jul 2020 21:23:15 -0400 Subject: [PATCH] More concise saving of data --- src/wireviz/wireviz.py | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index d8c4c1c..fe51cc7 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -199,18 +199,6 @@ def parse(yaml_input: str, return_types: (None, str, Tuple[str]) = None) -> Any: return tuple(returns) if len(returns) != 1 else returns[0] -def parse_file(yaml_file: str, file_out: (str, Path) = None) -> None: - with open_file_read(yaml_file) as file: - yaml_input = file.read() - - if not file_out: - fn, fext = os.path.splitext(yaml_file) - file_out = fn - file_out = os.path.abspath(file_out) - - parse(yaml_input, file_out=file_out) - - @click.command() @click.argument('input_file', required=True) @click.option('--prepend', '-p', default=None, help='a YAML file containing a library of templates and parts that may be referenced in the `input_file`') @@ -245,21 +233,18 @@ def main(input_file, prepend, out): # the parse function may return a single instance or a tuple, thus, the # if/then determines if there is only one thing that must be saved or multiple filedatas = parse(yaml_input, return_types=out) - if isinstance(filedatas, tuple): - for ext, data in zip(out, filedatas): - if 'csv' in ext: - extension = 'bom.csv' - elif 'tsv' in ext: - extension = 'bom.tsv' - else: - extension = ext - fname = f'{base_file_name}.{extension}' - with open(fname, 'wb') as f: - f.write(data) - else: - ext = out[0] - data = filedatas - fname = f'{base_file_name}.{ext}' + if not isinstance(filedatas, tuple): + filedatas = (filedatas, ) + + for ext, data in zip(out, filedatas): + if 'csv' in ext: + extension = 'bom.csv' + elif 'tsv' in ext: + extension = 'bom.tsv' + else: + extension = ext + + fname = f'{base_file_name}.{extension}' with open(fname, 'wb') as f: f.write(data)