From 66ce8debe534c6462576e25a24a38bed1d651c34 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 12 Mar 2022 14:25:58 -0800 Subject: [PATCH] fix merge errors --- jrnl/EncryptedJournal.py | 7 +++- jrnl/cli.py | 2 +- jrnl/editor.py | 6 +-- jrnl/exception.py | 85 ---------------------------------------- jrnl/install.py | 7 +++- jrnl/jrnl.py | 8 ++-- jrnl/messages.py | 50 +++++++++++++++++++++++ jrnl/upgrade.py | 9 +++-- 8 files changed, 74 insertions(+), 100 deletions(-) diff --git a/jrnl/EncryptedJournal.py b/jrnl/EncryptedJournal.py index 4440783e..08ca2397 100644 --- a/jrnl/EncryptedJournal.py +++ b/jrnl/EncryptedJournal.py @@ -22,7 +22,10 @@ from .Journal import LegacyJournal from .prompt import create_password from jrnl.exception import JrnlException -from jrnl.exception import JrnlExceptionMessage +from jrnl.messages import Message +from jrnl.messages import MsgText +from jrnl.messages import MsgType + def make_key(password): @@ -58,7 +61,7 @@ def decrypt_content( attempt += 1 if result is None: - raise JrnlException(JrnlExceptionMessage.PasswordMaxTriesExceeded) + raise JrnlException(Message(MsgText.PasswordMaxTriesExceeded, MsgType.ERROR)) return result diff --git a/jrnl/cli.py b/jrnl/cli.py index f0152775..eea9e97c 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -38,7 +38,7 @@ def cli(manual_args=None): except JrnlException as e: status_code = 1 - print_msg(e.title, e.message, msg=Message.ERROR) + e.print() except KeyboardInterrupt: status_code = 1 diff --git a/jrnl/editor.py b/jrnl/editor.py index c99c7cb8..481f1e13 100644 --- a/jrnl/editor.py +++ b/jrnl/editor.py @@ -5,8 +5,6 @@ import sys import tempfile from pathlib import Path -from jrnl.color import ERROR_COLOR -from jrnl.color import RESET_COLOR from jrnl.os_compat import on_windows from jrnl.os_compat import split_args from jrnl.output import print_msg @@ -33,7 +31,7 @@ def get_text_from_editor(config, template=""): subprocess.call(split_args(config["editor"]) + [tmpfile]) except FileNotFoundError: raise JrnlException( - JrnlExceptionMessage.EditorMisconfigured, editor_key=config["editor"] + Message(MsgText.EditorMisconfigured, MsgType.ERROR, { "editor_key": config["editor"] }) ) with open(tmpfile, "r", encoding="utf-8") as f: @@ -41,7 +39,7 @@ def get_text_from_editor(config, template=""): os.remove(tmpfile) if not raw: - raise JrnlException(JrnlExceptionMessage.NoTextReceived) + raise JrnlException(Message(MsgText.NoTextReceived, MsgType.ERROR)) return raw diff --git a/jrnl/exception.py b/jrnl/exception.py index 2b8c1a1b..fdfa61a4 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -3,91 +3,6 @@ from jrnl.messages import Message from jrnl.output import print_msg -from enum import Enum - - -class JrnlExceptionMessage(Enum): - ConfigDirectoryIsFile = """ - The path to your jrnl configuration directory is a file, not a directory: - - {config_directory_path} - - Removing this file will allow jrnl to save its configuration. - """ - - LineWrapTooSmallForDateFormat = """ - The provided linewrap value of {config_linewrap} is too small by - {columns} columns to display the timestamps in the configured time - format for journal {journal}. - - You can avoid this error by specifying a linewrap value that is larger - by at least {columns} in the configuration file or by using - --config-override at the command line - """ - - CannotEncryptJournalType = """ - The journal {journal_name} can't be encrypted because it is a - {journal_type} journal. - - To encrypt it, create a new journal referencing a file, export - this journal to the new journal, then encrypt the new journal. - """ - - KeyboardInterrupt = "Aborted by user" - - EditorMisconfigured = """ - No such file or directory: '{editor_key}' - - Please check the 'editor' key in your config file for errors: - editor: '{editor_key}' - """ - - JournalFailedUpgrade = """ - The following journal{s} failed to upgrade: - {failed_journals} - - Please tell us about this problem at the following URL: - https://github.com/jrnl-org/jrnl/issues/new?title=JournalFailedUpgrade - """ - - NothingToDelete = """ - No entries to delete, because the search returned no results. - """ - - NoTextReceived = """ - Nothing saved to file. - """ - - UpgradeAborted = """ - jrnl was NOT upgraded - """ - - EditorNotConfigured = """ - There is no editor configured. - - To use the --edit option, please specify an editor your config file: - {config_file} - - For examples of how to configure an external editor, see: - https://jrnl.sh/en/stable/external-editors/ - """ - - AltConfigNotFound = """ - Alternate configuration file not found at the given path: - {config_file} - """ - - PasswordMaxTriesExceeded = """ - Too many attempts with wrong password. - """ - - SomeTest = """ - Some error or something - - This is a thing to test with this message or whatever and maybe it just - keeps going forever because it's super long for no apparent reason - """ - class JrnlException(Exception): """Common exceptions raised by jrnl.""" diff --git a/jrnl/install.py b/jrnl/install.py index 59c832d4..5ec8d0cc 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -18,7 +18,10 @@ from .prompt import yesno from .upgrade import is_old_version from jrnl.exception import JrnlException -from jrnl.exception import JrnlExceptionMessage +from jrnl.messages import Message +from jrnl.messages import MsgText +from jrnl.messages import MsgType + def upgrade_config(config_data, alt_config_path=None): @@ -51,7 +54,7 @@ def find_default_config(): def find_alt_config(alt_config): if not os.path.exists(alt_config): raise JrnlException( - JrnlExceptionMessage.AltConfigNotFound, config_file=alt_config + Message(MsgText.AltConfigNotFound, MsgType.ERROR, { "config_file": alt_config }) ) return alt_config diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 0da0b57e..7dede648 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -16,7 +16,9 @@ from . import time from .override import apply_overrides from jrnl.exception import JrnlException -from jrnl.exception import JrnlExceptionMessage +from jrnl.messages import Message +from jrnl.messages import MsgText +from jrnl.messages import MsgType def run(args): @@ -134,7 +136,7 @@ def write_mode(args, config, journal, **kwargs): if not raw: logging.error("Write mode: couldn't get raw text") - raise JrnlException(JrnlExceptionMessage.NoTextReceived) + raise JrnlException(Message(MsgText.JrnlExceptionMessage.NoTextReceived, MsgType.ERROR)) logging.debug( 'Write mode: appending raw text to journal "%s": %s', args.journal_name, raw @@ -240,7 +242,7 @@ def _edit_search_results(config, journal, old_entries, **kwargs): """ if not config["editor"]: raise JrnlException( - JrnlExceptionMessage.EditorNotConfigured, config_file=get_config_path() + Message(MsgText.EditorNotConfigured, MsgType.ERROR, {"config_file": get_config_path()}) ) # separate entries we are not editing diff --git a/jrnl/messages.py b/jrnl/messages.py index eed0cbae..056e1d1f 100644 --- a/jrnl/messages.py +++ b/jrnl/messages.py @@ -72,6 +72,56 @@ class MsgText(Enum): HowToQuitWindows = "Ctrl+z and then Enter" HowToQuitLinux = "Ctrl+d" + EditorMisconfigured = """ + No such file or directory: '{editor_key}' + + Please check the 'editor' key in your config file for errors: + editor: '{editor_key}' + """ + + EditorNotConfigured = """ + There is no editor configured + + To use the --edit option, please specify an editor your config file: + {config_file} + + For examples of how to configure an external editor, see: + https://jrnl.sh/en/stable/external-editors/ + """ + + NoTextReceived = """ + Nothing saved to file + """ + + # --- Upgrade --- # + JournalFailedUpgrade = """ + The following journal{s} failed to upgrade: + {failed_journals} + + Please tell us about this problem at the following URL: + https://github.com/jrnl-org/jrnl/issues/new?title=JournalFailedUpgrade + """ + + UpgradeAborted = """ + jrnl was NOT upgraded + """ + + # -- Config --- # + AltConfigNotFound = """ + Alternate configuration file not found at the given path: + {config_file} + """ + + # --- Password --- # + PasswordMaxTriesExceeded = """ + Too many attempts with wrong password + """ + + # --- Search --- # + NothingToDelete = """ + No entries to delete, because the search returned no results + """ + class Message(NamedTuple): text: MsgText diff --git a/jrnl/upgrade.py b/jrnl/upgrade.py index a97b361e..761b18fa 100644 --- a/jrnl/upgrade.py +++ b/jrnl/upgrade.py @@ -13,9 +13,12 @@ from .config import scope_config from .prompt import yesno from jrnl.output import print_msg -from jrnl.output import Message + from jrnl.exception import JrnlException -from jrnl.exception import JrnlExceptionMessage +from jrnl.messages import Message +from jrnl.messages import MsgText +from jrnl.messages import MsgType + def backup(filename, binary=False): @@ -32,7 +35,7 @@ def backup(filename, binary=False): print(f"\nError: {filename} does not exist.") cont = yesno(f"\nCreate {filename}?", default=False) if not cont: - raise JrnlException(JrnlExceptionMessage.UpgradeAborted) + raise JrnlException(Message(MsgText.UpgradeAborted), MsgType.WARNING) def check_exists(path):