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
# License: https://www.gnu.org/licenses/gpl-3.0.html
import errno
import os
import re
import unicodedata
@ -53,6 +54,18 @@ class TextExporter:
def write_files(cls, journal, path):
"""Exports a journal into individual files for each entry."""
for entry in journal.entries:
full_path = os.path.join(path, cls.make_filename(entry))
try:
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))