Simplify file access operations
This commit is contained in:
parent
fbc90c0475
commit
c38305b3a5
@ -680,8 +680,7 @@ class Harness:
|
||||
# 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")
|
||||
|
||||
@ -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 = ""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user