From eeca1e23386f52161b123d2fb966ed5558be946e Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sun, 1 May 2022 10:39:08 -0700 Subject: [PATCH] update text_exporter with new message handling, get rid of old color constants --- jrnl/color.py | 4 --- jrnl/output.py | 2 -- jrnl/plugins/text_exporter.py | 48 ++++++++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/jrnl/color.py b/jrnl/color.py index 691cce9c..7cc8df2f 100644 --- a/jrnl/color.py +++ b/jrnl/color.py @@ -9,10 +9,6 @@ from .os_compat import on_windows if on_windows(): colorama.init() -WARNING_COLOR = colorama.Fore.YELLOW -ERROR_COLOR = colorama.Fore.RED -RESET_COLOR = colorama.Fore.RESET - def colorize(string, color, bold=False): """Returns the string colored with colorama.Fore.color. If the color set by diff --git a/jrnl/output.py b/jrnl/output.py index 8386f769..55ea7187 100644 --- a/jrnl/output.py +++ b/jrnl/output.py @@ -11,8 +11,6 @@ from rich.text import Text from rich import box from rich.console import Console -from jrnl.color import RESET_COLOR -from jrnl.color import WARNING_COLOR from jrnl.messages import Message from jrnl.messages import MsgType from jrnl.messages import MsgText diff --git a/jrnl/plugins/text_exporter.py b/jrnl/plugins/text_exporter.py index 4a5300df..51226f05 100644 --- a/jrnl/plugins/text_exporter.py +++ b/jrnl/plugins/text_exporter.py @@ -6,8 +6,10 @@ import os import re import unicodedata -from jrnl.color import ERROR_COLOR -from jrnl.color import RESET_COLOR +from jrnl.output import print_msg +from jrnl.messages import Message +from jrnl.messages import MsgText +from jrnl.messages import MsgType class TextExporter: @@ -29,14 +31,18 @@ class TextExporter: @classmethod def write_file(cls, journal, path): """Exports a journal into a single file.""" - try: - with open(path, "w", encoding="utf-8") as f: - f.write(cls.export_journal(journal)) - return f"[Journal exported to {path}]" - except IOError as e: - return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]" - except RuntimeError as e: - return e + with open(path, "w", encoding="utf-8") as f: + f.write(cls.export_journal(journal)) + print_msg( + Message( + MsgText.JournalExportedTo, + MsgType.NORMAL, + { + "path": path, + }, + ) + ) + return "" @classmethod def make_filename(cls, entry): @@ -48,17 +54,17 @@ class TextExporter: def write_files(cls, journal, path): """Exports a journal into individual files for each entry.""" for entry in journal.entries: - try: - 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)) - except IOError as e: - return "[{2}ERROR{3}: {0} {1}]".format( - e.filename, e.strerror, ERROR_COLOR, RESET_COLOR - ) - except RuntimeError as e: - return e - return "[Journal exported to {}]".format(path) + 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( + Message( + MsgText.JournalExportedTo, + MsgType.NORMAL, + {"path": path}, + ) + ) + return "" def _slugify(string): """Slugifies a string.