mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Handle KeyboardInterrupt when installing journal
This commit is contained in:
parent
e14910c83f
commit
bd806efb98
4 changed files with 24 additions and 8 deletions
|
@ -13,7 +13,7 @@ from . import Journal
|
||||||
from . import util
|
from . import util
|
||||||
from . import install
|
from . import install
|
||||||
from . import plugins
|
from . import plugins
|
||||||
from .util import ERROR_COLOR, RESET_COLOR
|
from .util import ERROR_COLOR, RESET_COLOR, UserAbort
|
||||||
import jrnl
|
import jrnl
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
@ -143,7 +143,12 @@ def run(manual_args=None):
|
||||||
print(util.py2encode(version_str))
|
print(util.py2encode(version_str))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
config = install.load_or_install_jrnl()
|
try:
|
||||||
|
config = install.load_or_install_jrnl()
|
||||||
|
except UserAbort as err:
|
||||||
|
util.prompt("\n{}".format(err))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if args.ls:
|
if args.ls:
|
||||||
util.prnt(list_journals(config))
|
util.prnt(list_journals(config))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from . import upgrade
|
||||||
from . import __version__
|
from . import __version__
|
||||||
from .Journal import PlainJournal
|
from .Journal import PlainJournal
|
||||||
from .EncryptedJournal import EncryptedJournal
|
from .EncryptedJournal import EncryptedJournal
|
||||||
|
from .util import UserAbort
|
||||||
import yaml
|
import yaml
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
@ -101,7 +102,11 @@ def load_or_install_jrnl():
|
||||||
return config
|
return config
|
||||||
else:
|
else:
|
||||||
log.debug('Configuration file not found, installing jrnl...')
|
log.debug('Configuration file not found, installing jrnl...')
|
||||||
return install()
|
try:
|
||||||
|
config = install()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise UserAbort("Installation aborted")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
|
|
|
@ -4,7 +4,7 @@ from . import __version__
|
||||||
from . import Journal
|
from . import Journal
|
||||||
from . import util
|
from . import util
|
||||||
from .EncryptedJournal import EncryptedJournal
|
from .EncryptedJournal import EncryptedJournal
|
||||||
import sys
|
from .util import UserAbort
|
||||||
import os
|
import os
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
|
@ -77,10 +77,12 @@ older versions of jrnl anymore.
|
||||||
for journal, path in other_journals.items():
|
for journal, path in other_journals.items():
|
||||||
util.prompt(" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name))
|
util.prompt(" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name))
|
||||||
|
|
||||||
cont = util.yesno("\nContinue upgrading jrnl?", default=False)
|
try:
|
||||||
if not cont:
|
cont = util.yesno("\nContinue upgrading jrnl?", default=False)
|
||||||
util.prompt("jrnl NOT upgraded, exiting.")
|
if not cont:
|
||||||
sys.exit(1)
|
raise KeyboardInterrupt
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise UserAbort("jrnl NOT upgraded, exiting.")
|
||||||
|
|
||||||
for journal_name, path in encrypted_journals.items():
|
for journal_name, path in encrypted_journals.items():
|
||||||
util.prompt("\nUpgrading encrypted '{}' journal stored in {}...".format(journal_name, path))
|
util.prompt("\nUpgrading encrypted '{}' journal stored in {}...".format(journal_name, path))
|
||||||
|
|
|
@ -47,6 +47,10 @@ SENTENCE_SPLITTER = re.compile(r"""
|
||||||
)""", re.UNICODE | re.VERBOSE)
|
)""", re.UNICODE | re.VERBOSE)
|
||||||
|
|
||||||
|
|
||||||
|
class UserAbort(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def getpass(prompt="Password: "):
|
def getpass(prompt="Password: "):
|
||||||
if not TEST:
|
if not TEST:
|
||||||
return gp.getpass(bytes(prompt))
|
return gp.getpass(bytes(prompt))
|
||||||
|
|
Loading…
Add table
Reference in a new issue