MCPcopy
hub / github.com/smittix/intercept / close

Method close

utils/sigmf.py:148–180  ·  view source on GitHub ↗

Flush data, write .sigmf-meta, close file. Returns ``(meta_path, data_path)`` on success, *None* if never opened or already aborted before any data was written.

(self)

Source from the content-addressed store, hash-verified

146 return True
147
148 def close(self) -> tuple[Path, Path] | None:
149 """Flush data, write .sigmf-meta, close file.
150
151 Returns ``(meta_path, data_path)`` on success, *None* if never
152 opened or already aborted before any data was written.
153 """
154 if self._data_file is not None:
155 try:
156 self._data_file.flush()
157 self._data_file.close()
158 except Exception:
159 pass
160 self._data_file = None
161
162 if self._data_path is None or self._meta_path is None:
163 return None
164 if self._bytes_written == 0 and not self._aborted:
165 # Nothing written — clean up empty file
166 self._data_path.unlink(missing_ok=True)
167 return None
168
169 try:
170 meta_dict = self._metadata.to_dict()
171 self._meta_path.write_text(
172 json.dumps(meta_dict, indent=2), encoding='utf-8'
173 )
174 except Exception as e:
175 logger.error(f"Failed to write SigMF metadata: {e}")
176
177 logger.info(
178 f"SigMFWriter closed: {self._bytes_written} bytes → {self._data_path}"
179 )
180 return self._meta_path, self._data_path
181
182 @property
183 def bytes_written(self) -> int:

Callers 15

_start_adsbMethod · 0.45
_adsb_sbs_readerMethod · 0.45
_start_pagerMethod · 0.45
_ais_tcp_readerMethod · 0.45
_start_aprsMethod · 0.45
close_dbFunction · 0.45
write_chunkMethod · 0.45
_rx_capture_loopMethod · 0.45
stop_receiveMethod · 0.45
_rtl433_writerMethod · 0.45
stop_allMethod · 0.45
_runMethod · 0.45

Calls 3

flushMethod · 0.80
to_dictMethod · 0.45
errorMethod · 0.45

Tested by 6

test_dump1090_startsMethod · 0.36
setup_dbMethod · 0.36
setup_dbMethod · 0.36
setup_dbFunction · 0.36
test_dbFunction · 0.36