@@ -110,6 +110,67 @@ def writeDetections(self, objects: list[Detection]) -> set[pathlib.Path]:
110110 )
111111 return written_files
112112
113+ def writeFbds (self ) -> set [pathlib .Path ]:
114+ written_files : set [pathlib .Path ] = set ()
115+
116+ # Path to the static FBD configuration file
117+ fbd_config_path = self .config .path / "static_configs" / "savedsearches_fbd.conf"
118+
119+ if not fbd_config_path .exists ():
120+ # If the file doesn't exist, just return empty set - no FBDs to write
121+ print ("No FBD configuration file found; skipping FBD writing to conf." )
122+ return written_files
123+ print (f"Reading FBD configuration from { fbd_config_path } " )
124+
125+ # Read and parse the FBD configuration file
126+ fbd_stanzas = self ._parse_fbd_config_file (fbd_config_path )
127+
128+ if fbd_stanzas : # Only write if there are actual stanzas
129+ written_files .add (
130+ ConfWriter .writeConfFile (
131+ pathlib .Path ("default/savedsearches.conf" ),
132+ "savedsearches_fbds.j2" ,
133+ self .config ,
134+ fbd_stanzas ,
135+ )
136+ )
137+
138+ return written_files
139+
140+ def _parse_fbd_config_file (self , file_path : pathlib .Path ) -> list :
141+ """Parse the FBD configuration file into individual stanza objects."""
142+ stanzas = []
143+ current_stanza_lines = []
144+
145+ with open (file_path , "r" , encoding = "utf-8" ) as f :
146+ for line in f :
147+ stripped_line = line .strip ()
148+
149+ # Skip comment lines (lines starting with # after stripping whitespace)
150+ if stripped_line .startswith ("#" ):
151+ continue
152+
153+ # If we hit a blank line and have accumulated stanza content, finalize the current stanza
154+ if not stripped_line :
155+ if current_stanza_lines :
156+ stanza_content = "\n " .join (current_stanza_lines )
157+ stanza_obj = type (
158+ "FbdStanza" , (), {"content" : stanza_content }
159+ )()
160+ stanzas .append (stanza_obj )
161+ current_stanza_lines = []
162+ continue
163+
164+ # Accumulate non-empty, non-comment lines for the current stanza
165+ current_stanza_lines .append (line .rstrip ())
166+ # Handle the last stanza if the file doesn't end with a blank line
167+ if current_stanza_lines :
168+ stanza_content = "\n " .join (current_stanza_lines )
169+ stanza_obj = type ("FbdStanza" , (), {"content" : stanza_content })()
170+ stanzas .append (stanza_obj )
171+
172+ return stanzas
173+
113174 def writeStories (self , objects : list [Story ]) -> set [pathlib .Path ]:
114175 written_files : set [pathlib .Path ] = set ()
115176 written_files .add (
0 commit comments