First try

This commit is contained in:
Jonathan van der Steege 2022-06-29 22:22:06 +02:00
parent 0279637fe4
commit e472d4e009

View file

@ -1,6 +1,7 @@
# Copyright (C) 2012-2022 jrnl contributors # Copyright (C) 2012-2022 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html # License: https://www.gnu.org/licenses/gpl-3.0.html
import errno
import os import os
import re import re
import unicodedata import unicodedata
@ -54,8 +55,20 @@ class TextExporter:
"""Exports a journal into individual files for each entry.""" """Exports a journal into individual files for each entry."""
for entry in journal.entries: for entry in journal.entries:
full_path = os.path.join(path, cls.make_filename(entry)) full_path = os.path.join(path, cls.make_filename(entry))
with open(full_path, "w", encoding="utf-8") as f: try:
f.write(cls.export_entry(entry)) with open(full_path, "w", encoding="utf-8") as f:
f.write(cls.export_entry(entry))
except OSError as oserr:
if oserr.errno != errno.ENAMETOOLONG:
raise
else:
print("Oops OSError!")
# ONLY AVAILABLE ON UNIX, SO FIX
max_file_length = os.statvfs(path).f_namemax - len(cls.extension) - 12
entry.title = str(entry.title)[:max_file_length]
full_path = os.path.join(path, cls.make_filename(entry))
with open(full_path, "w", encoding="utf-8") as f:
f.write(cls.export_entry(entry))
print_msg( print_msg(
Message( Message(
MsgText.JournalExportedTo, MsgText.JournalExportedTo,