Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contentctl/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto:
updated_conf_files.update(
conf_output.writeDetections(input_dto.director_output_dto.detections)
)
updated_conf_files.update(conf_output.writeFbds())
updated_conf_files.update(
conf_output.writeStories(input_dto.director_output_dto.stories)
)
Expand Down
61 changes: 61 additions & 0 deletions contentctl/output/conf_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,67 @@ def writeDetections(self, objects: list[Detection]) -> set[pathlib.Path]:
)
return written_files

def writeFbds(self) -> set[pathlib.Path]:
written_files: set[pathlib.Path] = set()

# Path to the static FBD configuration file
fbd_config_path = self.config.path / "static_configs" / "savedsearches_fbd.conf"

if not fbd_config_path.exists():
# If the file doesn't exist, just return empty set - no FBDs to write
print("No FBD configuration file found; skipping FBD writing to conf.")
return written_files
print(f"Reading FBD configuration from {fbd_config_path}")

# Read and parse the FBD configuration file
fbd_stanzas = self._parse_fbd_config_file(fbd_config_path)

if fbd_stanzas: # Only write if there are actual stanzas
written_files.add(
ConfWriter.writeConfFile(
pathlib.Path("default/savedsearches.conf"),
"savedsearches_fbds.j2",
self.config,
fbd_stanzas,
)
)

return written_files

def _parse_fbd_config_file(self, file_path: pathlib.Path) -> list:
"""Parse the FBD configuration file into individual stanza objects."""
stanzas = []
current_stanza_lines = []

with open(file_path, "r", encoding="utf-8") as f:
for line in f:
stripped_line = line.strip()

# Skip comment lines (lines starting with # after stripping whitespace)
if stripped_line.startswith("#"):
continue

# If we hit a blank line and have accumulated stanza content, finalize the current stanza
if not stripped_line:
if current_stanza_lines:
stanza_content = "\n".join(current_stanza_lines)
stanza_obj = type(
"FbdStanza", (), {"content": stanza_content}
)()
stanzas.append(stanza_obj)
current_stanza_lines = []
continue

# Accumulate non-empty, non-comment lines for the current stanza
current_stanza_lines.append(line.rstrip())
# Handle the last stanza if the file doesn't end with a blank line
if current_stanza_lines:
stanza_content = "\n".join(current_stanza_lines)
stanza_obj = type("FbdStanza", (), {"content": stanza_content})()
stanzas.append(stanza_obj)

return stanzas

def writeStories(self, objects: list[Story]) -> set[pathlib.Path]:
written_files: set[pathlib.Path] = set()
written_files.add(
Expand Down
9 changes: 9 additions & 0 deletions contentctl/output/templates/savedsearches_fbds.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


### {{app.label}} FBDS ###

{% for fbd_stanza in objects %}
{{ fbd_stanza.content }}

{% endfor %}
### END {{app.label}} FBDS ###
Loading