Don't create empty file when attempting a YAML export to a non-existing folder (#1600)

* Call `export_journal` before opening file handle
* Use correct exporter class
* Fix unit test
This commit is contained in:
outa 2022-10-08 22:48:29 +02:00 committed by GitHub
parent a925c81ba8
commit d7242d81a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View file

@ -31,18 +31,19 @@ class TextExporter:
@classmethod
def write_file(cls, journal, path):
"""Exports a journal into a single file."""
export_str = cls.export_journal(journal)
with open(path, "w", encoding="utf-8") as f:
f.write(cls.export_journal(journal))
print_msg(
Message(
MsgText.JournalExportedTo,
MsgStyle.NORMAL,
{
"path": path,
},
)
f.write(export_str)
print_msg(
Message(
MsgText.JournalExportedTo,
MsgStyle.NORMAL,
{
"path": path,
},
)
return ""
)
return ""
@classmethod
def make_filename(cls, entry):