mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 14:06:14 +02:00
Check for duplicate keys in config file (#1511)
* Check for duplicate keys in config file * Corrected BDD tests * Unneeded check removed * Make use of ruamel DuplicateKeyError exception * Remove unneeded import and function * slightly reword warning message * fix merge conflicts * update tests Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
parent
c45bed7f6c
commit
3a5316cedc
4 changed files with 71 additions and 4 deletions
|
@ -7,6 +7,7 @@ import os
|
|||
import colorama
|
||||
import xdg.BaseDirectory
|
||||
from ruamel.yaml import YAML
|
||||
from ruamel.yaml import constructor
|
||||
|
||||
from jrnl import __version__
|
||||
from jrnl.exception import JrnlException
|
||||
|
@ -159,10 +160,25 @@ def verify_config_colors(config):
|
|||
|
||||
def load_config(config_path):
|
||||
"""Tries to load a config file from YAML."""
|
||||
with open(config_path, encoding=YAML_FILE_ENCODING) as f:
|
||||
yaml = YAML(typ="safe")
|
||||
yaml.allow_duplicate_keys = True
|
||||
return yaml.load(f)
|
||||
try:
|
||||
with open(config_path, encoding=YAML_FILE_ENCODING) as f:
|
||||
yaml = YAML(typ="safe")
|
||||
yaml.allow_duplicate_keys = False
|
||||
return yaml.load(f)
|
||||
except constructor.DuplicateKeyError as e:
|
||||
print_msg(
|
||||
Message(
|
||||
MsgText.ConfigDoubleKeys,
|
||||
MsgStyle.WARNING,
|
||||
{
|
||||
"error_message": e,
|
||||
},
|
||||
)
|
||||
)
|
||||
with open(config_path, encoding=YAML_FILE_ENCODING) as f:
|
||||
yaml = YAML(typ="safe")
|
||||
yaml.allow_duplicate_keys = True
|
||||
return yaml.load(f)
|
||||
|
||||
|
||||
def is_config_json(config_path):
|
||||
|
|
|
@ -198,6 +198,13 @@ class MsgText(Enum):
|
|||
Configuration updated to newest version at {config_path}
|
||||
"""
|
||||
|
||||
ConfigDoubleKeys = """
|
||||
There is at least one duplicate key in your configuration file.
|
||||
|
||||
Details:
|
||||
{error_message}
|
||||
"""
|
||||
|
||||
# --- Password --- #
|
||||
Password = "Password:"
|
||||
PasswordFirstEntry = "Enter password for journal '{journal_name}': "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue