Skip to content

Commit

Permalink
Add function for generating Scenario sitemap Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
obsidianforensics committed Jun 27, 2024
1 parent 9ee0a31 commit 54f5cdc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion dfiq/dfiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def __init__(
}
self.components = {}
self.graph = None
self.templates_path = Path(templates_path)
logging.debug(f'"templates_path" set to "{self.templates_path.resolve()}"')
self.jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(templates_path), trim_blocks=True
)
Expand Down Expand Up @@ -584,6 +586,27 @@ def write_content_to_file(content: str, file_path: Path) -> None:
output_file.parent.mkdir(exist_ok=True, parents=True)
output_file.write_text(content, encoding="utf-8")

def generate_scenario_sitemap_md(self, allow_internal: bool = False) -> None:
"""Generates a Markdown sitemap for the Scenarios.
Args:
allow_internal (bool): Check if generating internal items is allowed.
"""
if not self.markdown_output_path:
raise ValueError("Markdown output path not specified")

template = self.jinja_env.get_template("scenario_sitemap.jinja2")
context = {
"components": self.components,
"allow_internal": allow_internal,
}

content = template.render(context)
output_path = Path(self.markdown_output_path, "scenarios", "sitemap.md")
output_file = Path(output_path)
output_file.parent.mkdir(exist_ok=True, parents=True)
output_file.write_text(content, encoding="utf-8")

def generate_question_index_md(self, allow_internal: bool = False) -> None:
"""Generates Markdown for the index page listing all Questions.
Expand Down Expand Up @@ -632,7 +655,7 @@ def generate_approach_glossary_md(self, allow_internal: bool = False) -> None:

for step in analysis["steps"]:
analysis_step_types.add(step["type"])
m = re.findall(r"\{.*?\}", step["value"])
m = re.findall(r"\{[A-z0-9_ -]{2,}?\}", step["value"])

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium

Suspicious character range that is equivalent to [A-Z\[\\]^_`a-z].
if m:
step_variables.update(m)

Expand Down

0 comments on commit 54f5cdc

Please sign in to comment.