Utilities¶
- kable.utils.get_icon_and_file(file)[source]¶
Get a Nerd Font icon and filename for display.
- Parameters:
file (Path) – The file or directory to represent.
- Returns:
A formatted string containing an icon and filename.
- Return type:
str
- kable.utils.checksum(text)[source]¶
Calculate a SHA-256 checksum.
- Parameters:
text (str | bytes) – The text or bytes to hash.
- Returns:
The hexadecimal SHA-256 digest.
- Return type:
str
- kable.utils.safe_file_read(file, json=False, exit=True)[source]¶
Read a file safely.
- Parameters:
file (Path) – The file to read.
json (bool) – Whether to parse the file as JSON.
exit (bool) – Whether to raise exceptions on failure.
- Returns:
The file contents, parsed JSON object, or None on failure when
exitis False.- Raises:
Exception – If the file cannot be read and
exitis True.
- kable.utils.safe_file_write(file, data, json=False)[source]¶
Write data to a file safely.
- Parameters:
file (Path) – The file to write to.
data – The data to write.
json (bool) – Whether to serialize the data as JSON.
- Raises:
Exception – If the file cannot be written.
- kable.utils.run_git_command(*args, return_process=False)[source]¶
Execute a Git command.
- Parameters:
args – Arguments to pass to Git.
return_process (bool) – Whether to return the process object instead of command output.
- Returns:
Command output, a CompletedProcess, or a CalledProcessError depending on the arguments and execution result.
- Return type:
str | CompletedProcess | CalledProcessError