mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
update upgrade module journal summaries to use new message handling
This commit is contained in:
parent
93650f9927
commit
1b6c3edbd3
2 changed files with 65 additions and 31 deletions
|
@ -157,6 +157,17 @@ class MsgText(Enum):
|
||||||
|
|
||||||
ImportAborted = "Entries were NOT imported"
|
ImportAborted = "Entries were NOT imported"
|
||||||
|
|
||||||
|
JournalsToUpgrade = """
|
||||||
|
The following {journal_type} journals will be upgraded to jrnl {version}:
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
JournalsToIgnore = """
|
||||||
|
The following journals will not be touched:
|
||||||
|
|
||||||
|
"""
|
||||||
|
PaddedJournalName = "{journal_name:{pad}} -> {path}"
|
||||||
|
|
||||||
# -- Config --- #
|
# -- Config --- #
|
||||||
AltConfigNotFound = """
|
AltConfigNotFound = """
|
||||||
Alternate configuration file not found at the given path:
|
Alternate configuration file not found at the given path:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from .config import scope_config
|
||||||
from .prompt import yesno
|
from .prompt import yesno
|
||||||
|
|
||||||
from jrnl.output import print_msg
|
from jrnl.output import print_msg
|
||||||
|
from jrnl.output import print_msgs
|
||||||
from jrnl.exception import JrnlException
|
from jrnl.exception import JrnlException
|
||||||
from jrnl.messages import Message
|
from jrnl.messages import Message
|
||||||
from jrnl.messages import MsgText
|
from jrnl.messages import MsgText
|
||||||
|
@ -36,9 +37,7 @@ def backup(filename, binary=False):
|
||||||
)
|
)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print_msg(
|
print_msg(Message(MsgText.DoesNotExist, MsgType.WARNING, {"name": filename}))
|
||||||
Message(MsgText.DoesNotExist, MsgType.WARNING, {"name": filename})
|
|
||||||
)
|
|
||||||
cont = yesno(f"\nCreate {filename}?", default=False)
|
cont = yesno(f"\nCreate {filename}?", default=False)
|
||||||
if not cont:
|
if not cont:
|
||||||
raise JrnlException(Message(MsgText.UpgradeAborted, MsgType.WARNING))
|
raise JrnlException(Message(MsgText.UpgradeAborted, MsgType.WARNING))
|
||||||
|
@ -83,36 +82,41 @@ def upgrade_jrnl(config_path):
|
||||||
else:
|
else:
|
||||||
plain_journals[journal_name] = path
|
plain_journals[journal_name] = path
|
||||||
|
|
||||||
longest_journal_name = max([len(journal) for journal in config["journals"]])
|
kwargs = {
|
||||||
if encrypted_journals:
|
# longest journal name
|
||||||
print(
|
"pad": max([len(journal) for journal in config["journals"]]),
|
||||||
f"\nFollowing encrypted journals will be upgraded to jrnl {__version__}:",
|
"version": __version__,
|
||||||
file=sys.stderr,
|
}
|
||||||
)
|
|
||||||
for journal, path in encrypted_journals.items():
|
|
||||||
print(
|
|
||||||
" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name),
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
|
|
||||||
if plain_journals:
|
_print_journal_summary(
|
||||||
print(
|
journals=encrypted_journals,
|
||||||
f"\nFollowing plain text journals will upgraded to jrnl {__version__}:",
|
header=Message(
|
||||||
file=sys.stderr,
|
MsgText.JournalsToUpgrade,
|
||||||
)
|
params={
|
||||||
for journal, path in plain_journals.items():
|
"journal_type": "encrypted",
|
||||||
print(
|
"version": __version__,
|
||||||
" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name),
|
},
|
||||||
file=sys.stderr,
|
),
|
||||||
)
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
if other_journals:
|
_print_journal_summary(
|
||||||
print("\nFollowing journals will be not be touched:", file=sys.stderr)
|
journals=plain_journals,
|
||||||
for journal, path in other_journals.items():
|
header=Message(
|
||||||
print(
|
MsgText.JournalsToUpgrade,
|
||||||
" {:{pad}} -> {}".format(journal, path, pad=longest_journal_name),
|
params={
|
||||||
file=sys.stderr,
|
"journal_type": "plain text",
|
||||||
)
|
"version": __version__,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
_print_journal_summary(
|
||||||
|
journals=other_journals,
|
||||||
|
header=Message(MsgText.JournalsToIgnore),
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
cont = yesno("\nContinue upgrading jrnl?", default=False)
|
cont = yesno("\nContinue upgrading jrnl?", default=False)
|
||||||
if not cont:
|
if not cont:
|
||||||
|
@ -169,3 +173,22 @@ def upgrade_jrnl(config_path):
|
||||||
|
|
||||||
def is_old_version(config_path):
|
def is_old_version(config_path):
|
||||||
return is_config_json(config_path)
|
return is_config_json(config_path)
|
||||||
|
|
||||||
|
|
||||||
|
def _print_journal_summary(journals: dict, header: Message, pad: int) -> None:
|
||||||
|
if not journals:
|
||||||
|
return
|
||||||
|
|
||||||
|
msgs = [header]
|
||||||
|
for journal, path in journals.items():
|
||||||
|
msgs.append(
|
||||||
|
Message(
|
||||||
|
MsgText.PaddedJournalName,
|
||||||
|
params={
|
||||||
|
"journal_name": journal,
|
||||||
|
"path": path,
|
||||||
|
"pad": pad,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
print_msgs(msgs)
|
||||||
|
|
Loading…
Add table
Reference in a new issue