mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-11 17:18:30 +02:00
[GH-632] raising exception in upgrade.py on fail
Handling it in install.py to prevent config from being overwritten when upgrade fails
This commit is contained in:
parent
3bfd9f487b
commit
a4e881942a
2 changed files with 16 additions and 2 deletions
|
@ -14,6 +14,7 @@ from .Journal import PlainJournal
|
||||||
from .EncryptedJournal import EncryptedJournal
|
from .EncryptedJournal import EncryptedJournal
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
DEFAULT_CONFIG_NAME = 'jrnl.yaml'
|
DEFAULT_CONFIG_NAME = 'jrnl.yaml'
|
||||||
DEFAULT_JOURNAL_NAME = 'journal.txt'
|
DEFAULT_JOURNAL_NAME = 'journal.txt'
|
||||||
|
@ -85,8 +86,15 @@ def load_or_install_jrnl():
|
||||||
if os.path.exists(config_path):
|
if os.path.exists(config_path):
|
||||||
log.debug('Reading configuration from file %s', config_path)
|
log.debug('Reading configuration from file %s', config_path)
|
||||||
config = util.load_config(config_path)
|
config = util.load_config(config_path)
|
||||||
upgrade.upgrade_jrnl_if_necessary(config_path)
|
|
||||||
|
try:
|
||||||
|
upgrade.upgrade_jrnl_if_necessary(config_path)
|
||||||
|
except upgrade.UpgradeValidationException:
|
||||||
|
util.prompt("Aborting upgrade. Exiting.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
upgrade_config(config)
|
upgrade_config(config)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
else:
|
else:
|
||||||
log.debug('Configuration file not found, installing jrnl...')
|
log.debug('Configuration file not found, installing jrnl...')
|
||||||
|
|
|
@ -96,12 +96,14 @@ older versions of jrnl anymore.
|
||||||
|
|
||||||
# loop through lists to validate
|
# loop through lists to validate
|
||||||
failed_journals = [j for j in all_journals if not j.validate_parsing()]
|
failed_journals = [j for j in all_journals if not j.validate_parsing()]
|
||||||
|
|
||||||
if len(failed_journals) > 0:
|
if len(failed_journals) > 0:
|
||||||
util.prompt("\nThe following journal{} failed to upgrade:\n{}".format(
|
util.prompt("\nThe following journal{} failed to upgrade:\n{}".format(
|
||||||
's' if len(failed_journals) > 1 else '', "\n".join(j.name for j in failed_journals))
|
's' if len(failed_journals) > 1 else '', "\n".join(j.name for j in failed_journals))
|
||||||
)
|
)
|
||||||
|
|
||||||
util.prompt("Aborting upgrade.")
|
raise UpgradeValidationException
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# write all journals - or - don't
|
# write all journals - or - don't
|
||||||
|
@ -112,3 +114,7 @@ older versions of jrnl anymore.
|
||||||
backup(config_path)
|
backup(config_path)
|
||||||
|
|
||||||
util.prompt("\nWe're all done here and you can start enjoying jrnl 2.".format(config_path))
|
util.prompt("\nWe're all done here and you can start enjoying jrnl 2.".format(config_path))
|
||||||
|
|
||||||
|
class UpgradeValidationException(Exception):
|
||||||
|
"""Raised when the contents of an upgraded journal do not match the old journal"""
|
||||||
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue