mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +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):
|
def write_files(cls, journal, path):
|
||||||
"""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:
|
||||||
|
entry_is_written = False
|
||||||
|
while not entry_is_written:
|
||||||
full_path = os.path.join(path, cls.make_filename(entry))
|
full_path = os.path.join(path, cls.make_filename(entry))
|
||||||
try:
|
try:
|
||||||
with open(full_path, "w", encoding="utf-8") as f:
|
with open(full_path, "w", encoding="utf-8") as f:
|
||||||
f.write(cls.export_entry(entry))
|
f.write(cls.export_entry(entry))
|
||||||
|
entry_is_written = True
|
||||||
except OSError as oserr:
|
except OSError as oserr:
|
||||||
if oserr.errno != errno.ENAMETOOLONG:
|
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
|
raise
|
||||||
else:
|
else:
|
||||||
print("Oops OSError!")
|
raise
|
||||||
# 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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue