eb8dbf66a1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Borra una nota de Obsidian (.md) del disco.
|
|
|
|
Funcion impura: elimina un archivo del sistema de archivos. Por seguridad solo
|
|
borra archivos, nunca directorios.
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
def delete_obsidian_note(path: str) -> bool:
|
|
"""Borra un archivo de nota Markdown de Obsidian.
|
|
|
|
Args:
|
|
path: ruta al archivo .md a borrar.
|
|
|
|
Returns:
|
|
True si el archivo fue borrado correctamente.
|
|
|
|
Raises:
|
|
FileNotFoundError: si el archivo no existe.
|
|
IsADirectoryError: si la ruta apunta a un directorio (nunca se borra un
|
|
directorio, solo un archivo concreto).
|
|
OSError: si el borrado falla por otro motivo de I/O.
|
|
"""
|
|
if not os.path.exists(path):
|
|
raise FileNotFoundError(f"obsidian note not found: {path}")
|
|
if os.path.isdir(path):
|
|
raise IsADirectoryError(
|
|
f"refusing to delete a directory, only single files: {path}"
|
|
)
|
|
|
|
os.remove(path)
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import tempfile
|
|
|
|
fd, tmp = tempfile.mkstemp(suffix=".md")
|
|
os.close(fd)
|
|
assert delete_obsidian_note(tmp) is True
|
|
assert not os.path.exists(tmp)
|
|
try:
|
|
delete_obsidian_note(tmp)
|
|
raise AssertionError("debio lanzar FileNotFoundError")
|
|
except FileNotFoundError:
|
|
pass
|
|
print("delete_obsidian_note smoke OK")
|