Skip to main content

KernelDB.scan_directory()

Recursively scan a directory tree and register all kernel files.

Usage

Source

KernelDB.scan_directory(
    root,
    mission=None,
    extensions=None,
    verbose=False,
    archive=False,
    archive_roots=None
)

Files are registered with register_file. Every .tm file found is also indexed and added to the metakernel registry.

If mission is not given, it is detected for each file from its path with guess_mission and the database’s kernel roots: under a root, the first directory below the root; elsewhere, the path structure (.../<MISSION>/kernels/...). register_file guesses the same way when it is given no mission.

With archive, each file is moved into a kernel root, laid out as <root>/<mission>/<type>/<filename>, and a symlink is left at the original location. The root is the file’s own when it already sits in a configured root, else root_for of its mission (2026-11-21). Every file’s root is settled before anything moves, so an AmbiguousKernelRoot leaves the tree untouched. archive_roots ({mission: root}) is how the CLI answers it and calls again. scan_roots takes the same two arguments.

Parameters

root: str | Path

The directory to scan.

mission: str | None = None

File everything under this mission instead of detecting it.

extensions: set[str] | None = None

The file extensions to register, lowercase and with the dot. None means every known SPICE kernel extension: .bc, .bsp, .bpc, .tpc, .tf, .ti, .tls, .tsc, .bds and .tm.

verbose: bool = False

Write each registered file name on the instance’s console, if it has one.

archive: bool = False

Move the files into a kernel root, as described above.

archive_roots: dict[str, Path] | None = None
The root to use for each mission when archive is set and root_for cannot decide.

Returns

tuple[int, set[str]]
(count, missions_found): the number of files registered and the set of mission names detected during the scan.

Raises

AmbiguousKernelRoot
With archive, a file outside the roots belongs to a mission that root_for cannot place and archive_roots does not answer.