Simplify file access operations
This commit is contained in:
parent
45bcc1dd45
commit
d19c260940
@ -680,8 +680,7 @@ class Harness:
|
|||||||
# BOM output
|
# BOM output
|
||||||
bomlist = bom_list(self.bom())
|
bomlist = bom_list(self.bom())
|
||||||
if "tsv" in fmt:
|
if "tsv" in fmt:
|
||||||
with open_file_write(f"{filename}.bom.tsv") as file:
|
open_file_write(f"{filename}.bom.tsv").write(tuplelist2tsv(bomlist))
|
||||||
file.write(tuplelist2tsv(bomlist))
|
|
||||||
if "csv" in fmt:
|
if "csv" in fmt:
|
||||||
# TODO: implement CSV output (preferrably using CSV library)
|
# TODO: implement CSV output (preferrably using CSV library)
|
||||||
print("CSV output is not yet supported")
|
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}")
|
raise Exception(f"File does not exist:\n{prepend_file}")
|
||||||
print("Prepend file:", prepend_file)
|
print("Prepend file:", prepend_file)
|
||||||
|
|
||||||
with open_file_read(prepend_file) as file_handle:
|
prepend_input += open_file_read(prepend_file).read() + "\n"
|
||||||
prepend_input += file_handle.read() + "\n"
|
|
||||||
else:
|
else:
|
||||||
prepend_input = ""
|
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}"
|
"Output file: ", f"{Path(_output_dir / _output_name)}.{output_formats_str}"
|
||||||
)
|
)
|
||||||
|
|
||||||
with open_file_read(file) as file_handle:
|
yaml_input = open_file_read(file).read()
|
||||||
yaml_input = file_handle.read()
|
|
||||||
file_dir = file.parent
|
file_dir = file.parent
|
||||||
|
|
||||||
yaml_input = prepend_input + yaml_input
|
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
|
# fall back to built-in simple template if no template was provided
|
||||||
templatefile = Path(__file__).parent / "templates/simple.html"
|
templatefile = Path(__file__).parent / "templates/simple.html"
|
||||||
|
|
||||||
with open_file_read(templatefile) as file:
|
html = open_file_read(templatefile).read()
|
||||||
html = file.read()
|
|
||||||
|
|
||||||
# embed SVG diagram
|
# embed SVG diagram
|
||||||
with open_file_read(f"{filename}.svg") as file:
|
with open_file_read(f"{filename}.svg") as file:
|
||||||
@ -117,5 +116,4 @@ def generate_html_output(
|
|||||||
pattern = re.compile("|".join(replacements_escaped))
|
pattern = re.compile("|".join(replacements_escaped))
|
||||||
html = pattern.sub(lambda match: replacements[match.group(0)], html)
|
html = pattern.sub(lambda match: replacements[match.group(0)], html)
|
||||||
|
|
||||||
with open_file_write(f"{filename}.html") as file:
|
open_file_write(f"{filename}.html").write(html)
|
||||||
file.write(html)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user