Exporters¶
Exports go through the get_exporter factory, which returns a BaseExporter subclass for the requested format. Call its export method with an output path. The output of each format is described in Export Formats.
Registry¶
recursivist.exporters
¶
Exporter registry.
Maps each supported export format to its exporter class and exposes
get_exporter, the factory used to construct the
right exporter for a requested format.
supported_formats
¶
Return the export format identifiers accepted by
get_exporter.
This is the single source of truth for which formats are valid; callers (e.g. the CLI) should derive their validation from it rather than hard-coding a list.
Returns:
| Type | Description |
|---|---|
list[str]
|
The supported format identifiers, sorted for stable presentation. Alias keys are |
list[str]
|
included, so both |
Source code in recursivist/exporters/__init__.py
canonical_extension
¶
Return the canonical output file extension for a format identifier.
The extension is read from the exporter class, so aliases that share an exporter collapse to a single extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format_type
|
str
|
Export format identifier (e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The exporter's canonical file extension, without a leading dot (e.g. |
str
|
for both |
str
|
format_type for unknown formats, mirroring |
str
|
|
Source code in recursivist/exporters/__init__.py
get_exporter
¶
get_exporter(format_type: str, **kwargs: Any) -> BaseExporter
Construct the exporter for a given format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format_type
|
str
|
Export format identifier (e.g. |
required |
**kwargs
|
Any
|
Keyword arguments forwarded to the exporter's constructor (see
|
{}
|
Returns:
| Type | Description |
|---|---|
BaseExporter
|
A ready-to-use exporter instance; call its |
BaseExporter
|
file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If format_type is not a supported format. |
Source code in recursivist/exporters/__init__.py
Base Exporter¶
recursivist.exporters.base
¶
Shared base class for directory-structure exporters.
Defines BaseExporter, which stores the
scanned structure and the resolved display options common to every output format.
Concrete exporters subclass it and implement
BaseExporter.export.
write_text is the single place export files
are written: it makes undecodable file names encodable and writes atomically, so every
format behaves the same way.
BaseExporter
¶
Common base for the per-format exporters.
Holds the scanned structure and the resolved
DisplayOptions; the actual output is produced
by each subclass's export. For
convenience, the individual pieces of the spec are also exposed as plain attributes
(metrics, sort_key,
show_loc/show_size/show_mtime/show_git_status) so exporters can read
them directly.
Attributes:
| Name | Type | Description |
|---|---|---|
extension |
str
|
Canonical file extension for this format, without a leading dot (e.g.
|
Source code in recursivist/exporters/base.py
__init__
¶
__init__(structure: Directory, root_name: str, show_full_path: bool = False, spec: DisplayOptions | None = None, icon_style: str = 'emoji') -> None
Store the structure and display options for an export.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Directory
|
Scanned directory structure to export. |
required |
root_name
|
str
|
Display name of the root directory. |
required |
show_full_path
|
bool
|
Whether structure holds absolute paths (or GitHub blob URLs) to display instead of bare filenames. |
False
|
spec
|
DisplayOptions | None
|
Resolved sorting and annotation directives. Defaults to a plain
|
None
|
icon_style
|
str
|
Icon style to use, either |
'emoji'
|
Source code in recursivist/exporters/base.py
export
¶
Write the export to output_path.
Subclasses must override this method; the base implementation always raises
NotImplementedError.
Source code in recursivist/exporters/base.py
write_text
¶
Atomically write text to output_path as UTF-8.
Lone surrogates, which stand in for the undecodable bytes of a non-UTF-8 file name, are replaced with U+FFFD so the text always encodes.
The text is written to a temporary file in the destination directory, which is then
renamed over the destination. A failure at any point leaves an existing file
untouched and creates no partial one. Symbolic links are followed and the
permissions of a file being overwritten are kept, as with a plain open. A
destination that exists but is not a regular file (such as /dev/stdout) cannot
be replaced, so it is written to directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str
|
Path the file is written to. |
required |
text
|
str
|
Content to write. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be written. |