Merge 605ee2a1f7277eaae858f1223dc8db466315f575 into e4fe099f8c7b86736aee7b4227cc794b6e8b36f0
This commit is contained in:
commit
6386496d13
@ -666,6 +666,7 @@ class Harness:
|
|||||||
view: bool = False,
|
view: bool = False,
|
||||||
cleanup: bool = True,
|
cleanup: bool = True,
|
||||||
fmt: tuple = ("html", "png", "svg", "tsv"),
|
fmt: tuple = ("html", "png", "svg", "tsv"),
|
||||||
|
templatedir: (str, Path) = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
# graphical output
|
# graphical output
|
||||||
graph = self.graph
|
graph = self.graph
|
||||||
@ -697,7 +698,7 @@ class Harness:
|
|||||||
print("CSV output is not yet supported")
|
print("CSV output is not yet supported")
|
||||||
# HTML output
|
# HTML output
|
||||||
if "html" in fmt:
|
if "html" in fmt:
|
||||||
generate_html_output(filename, bomlist, self.metadata, self.options)
|
generate_html_output(filename, bomlist, self.metadata, self.options, templatedir=templatedir)
|
||||||
# PDF output
|
# PDF output
|
||||||
if "pdf" in fmt:
|
if "pdf" in fmt:
|
||||||
# TODO: implement PDF output
|
# TODO: implement PDF output
|
||||||
|
|||||||
@ -31,6 +31,7 @@ def parse(
|
|||||||
output_dir: Union[str, Path] = None,
|
output_dir: Union[str, Path] = None,
|
||||||
output_name: Union[None, str] = None,
|
output_name: Union[None, str] = None,
|
||||||
image_paths: Union[Path, str, List] = [],
|
image_paths: Union[Path, str, List] = [],
|
||||||
|
template_dir: Union[str, Path] = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""
|
"""
|
||||||
This function takes an input, parses it as a WireViz Harness file,
|
This function takes an input, parses it as a WireViz Harness file,
|
||||||
@ -382,7 +383,7 @@ def parse(
|
|||||||
harness.add_bom_item(line)
|
harness.add_bom_item(line)
|
||||||
|
|
||||||
if output_formats:
|
if output_formats:
|
||||||
harness.output(filename=output_file, fmt=output_formats, view=False)
|
harness.output(filename=output_file, fmt=output_formats, view=False, templatedir=template_dir)
|
||||||
|
|
||||||
if return_types:
|
if return_types:
|
||||||
returns = []
|
returns = []
|
||||||
|
|||||||
@ -64,6 +64,13 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
|
|||||||
type=str,
|
type=str,
|
||||||
help="File name (without extension) to use for output files, if different from input file name.",
|
help="File name (without extension) to use for output files, if different from input file name.",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"-t",
|
||||||
|
"--template-dir",
|
||||||
|
default=None,
|
||||||
|
type=Path,
|
||||||
|
help="Directory to look into for html template file (optional)",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-V",
|
"-V",
|
||||||
"--version",
|
"--version",
|
||||||
@ -71,7 +78,7 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
|
|||||||
default=False,
|
default=False,
|
||||||
help=f"Output {APP_NAME} version and exit.",
|
help=f"Output {APP_NAME} version and exit.",
|
||||||
)
|
)
|
||||||
def wireviz(file, format, prepend, output_dir, output_name, version):
|
def wireviz(file, format, prepend, output_dir, output_name, template_dir, version):
|
||||||
"""
|
"""
|
||||||
Parses the provided FILE and generates the specified outputs.
|
Parses the provided FILE and generates the specified outputs.
|
||||||
"""
|
"""
|
||||||
@ -144,6 +151,7 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
|
|||||||
output_dir=_output_dir,
|
output_dir=_output_dir,
|
||||||
output_name=_output_name,
|
output_name=_output_name,
|
||||||
image_paths=list(image_paths),
|
image_paths=list(image_paths),
|
||||||
|
template_dir=template_dir,
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|||||||
@ -21,14 +21,23 @@ def generate_html_output(
|
|||||||
bom_list: List[List[str]],
|
bom_list: List[List[str]],
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
options: Options,
|
options: Options,
|
||||||
|
templatedir: Union[str, Path],
|
||||||
):
|
):
|
||||||
|
print("Test")
|
||||||
# load HTML template
|
# load HTML template
|
||||||
templatename = metadata.get("template", {}).get("name")
|
templatename = metadata.get("template", {}).get("name")
|
||||||
if templatename:
|
if templatename:
|
||||||
|
templatedirs = []
|
||||||
|
|
||||||
|
# if template directory is provided, add it to the lookup paths
|
||||||
|
if templatedir is not None:
|
||||||
|
templatedirs.append(templatedir)
|
||||||
# if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory
|
# if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory
|
||||||
|
templatedirs.extend([Path(filename).parent, Path(__file__).parent / "templates"])
|
||||||
|
|
||||||
templatefile = smart_file_resolve(
|
templatefile = smart_file_resolve(
|
||||||
f"{templatename}.html",
|
f"{templatename}.html",
|
||||||
[Path(filename).parent, Path(__file__).parent / "templates"],
|
templatedirs,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# fall back to built-in simple template if no template was provided
|
# fall back to built-in simple template if no template was provided
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user