mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
Make cross platform solution
This commit is contained in:
parent
e472d4e009
commit
6c6ae30c13
1 changed files with 15 additions and 13 deletions
|
@ -54,21 +54,23 @@ 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))
|
||||
entry_is_written = False
|
||||
while not entry_is_written:
|
||||
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))
|
||||
entry_is_written = True
|
||||
except OSError as oserr:
|
||||
if oserr.errno == errno.ENAMETOOLONG:
|
||||
title_length = len(str(entry.title))
|
||||
if title_length > 1:
|
||||
shorter_file_length = title_length // 2
|
||||
entry.title = str(entry.title)[:shorter_file_length]
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
print_msg(
|
||||
Message(
|
||||
MsgText.JournalExportedTo,
|
||||
|
|
Loading…
Add table
Reference in a new issue