29 lines
874 B
Python
29 lines
874 B
Python
from pathlib import Path
|
|
from tempfile import NamedTemporaryFile
|
|
|
|
from sh import age
|
|
from halig.config import Config
|
|
from halig.utils import wait_for_editor
|
|
|
|
|
|
def edit_note(note_path: Path, config: Config):
|
|
"""Edit an existing note. This method assumes that `note_path` exists, is
|
|
a fully-formed, absolute path and an age file inside the configured notebooks
|
|
|
|
Args:
|
|
note_path (Path): The path to the note to edit
|
|
config (Config): config object
|
|
"""
|
|
|
|
note_contents = age("-d", "-i", config.encryption_keys.private_key_path, note_path)
|
|
|
|
with NamedTemporaryFile(delete=False) as tmpfile:
|
|
tmpfile.write(str(note_contents).encode())
|
|
wait_for_editor(tmpfile.name)
|
|
age(
|
|
"-R",
|
|
str(config.encryption_keys.public_key_path),
|
|
tmpfile.name,
|
|
_out=str(note_path),
|
|
)
|
|
Path(tmpfile.name).unlink()
|