mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
First try
This commit is contained in:
parent
0279637fe4
commit
e472d4e009
1 changed files with 15 additions and 2 deletions
|
@ -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
|
||||||
|
@ -53,6 +54,18 @@ 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:
|
||||||
|
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))
|
full_path = os.path.join(path, cls.make_filename(entry))
|
||||||
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))
|
||||||
|
|
Loading…
Add table
Reference in a new issue