Skip to content

Commit

Permalink
Simplify file access operations
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Oct 16, 2021
1 parent e59239b commit 9a03e5e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ def output(
# BOM output
bomlist = bom_list(self.bom())
if "tsv" in fmt:
with open_file_write(f"{filename}.bom.tsv") as file:
file.write(tuplelist2tsv(bomlist))
open_file_write(f"{filename}.bom.tsv").write(tuplelist2tsv(bomlist))
if "csv" in fmt:
# TODO: implement CSV output (preferrably using CSV library)
print("CSV output is not yet supported")
Expand Down
6 changes: 2 additions & 4 deletions src/wireviz/wv_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
raise Exception(f"File does not exist:\n{prepend_file}")
print("Prepend file:", prepend_file)

with open_file_read(prepend_file) as file_handle:
prepend_input += file_handle.read() + "\n"
prepend_input += open_file_read(prepend_file).read() + "\n"
else:
prepend_input = ""

Expand All @@ -127,8 +126,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
"Output file: ", f"{Path(_output_dir / _output_name)}.{output_formats_str}"
)

with open_file_read(file) as file_handle:
yaml_input = file_handle.read()
yaml_input = open_file_read(file).read()
file_dir = file.parent

yaml_input = prepend_input + yaml_input
Expand Down
6 changes: 2 additions & 4 deletions src/wireviz/wv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def generate_html_output(
# fall back to built-in simple template if no template was provided
templatefile = Path(__file__).parent / "templates/simple.html"

with open_file_read(templatefile) as file:
html = file.read()
html = open_file_read(templatefile).read()

# embed SVG diagram
with open_file_read(f"{filename}.svg") as file:
Expand Down Expand Up @@ -117,5 +116,4 @@ def generate_html_output(
pattern = re.compile("|".join(replacements_escaped))
html = pattern.sub(lambda match: replacements[match.group(0)], html)

with open_file_write(f"{filename}.html") as file:
file.write(html)
open_file_write(f"{filename}.html").write(html)

0 comments on commit 9a03e5e

Please sign in to comment.