mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Fix for upgrade with missing journal
This commit is contained in:
parent
9d9f61ac1e
commit
2bafc8023b
3 changed files with 41 additions and 4 deletions
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"default_hour": 9,
|
||||||
|
"timeformat": "%Y-%m-%d %H:%M",
|
||||||
|
"linewrap": 80,
|
||||||
|
"encrypt": false,
|
||||||
|
"editor": "",
|
||||||
|
"default_minute": 0,
|
||||||
|
"highlight": true,
|
||||||
|
"journals": {"default": "features/journals/simple_jrnl-1-9-5.journal", "missing": "features/journals/missing.journal"},
|
||||||
|
"tagsymbols": "@"
|
||||||
|
}
|
|
@ -35,3 +35,16 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
||||||
10.06.2013 15:40 He said "[this] is the best time to be alive".
|
10.06.2013 15:40 He said "[this] is the best time to be alive".
|
||||||
"""
|
"""
|
||||||
Then the journal should have 2 entries
|
Then the journal should have 2 entries
|
||||||
|
|
||||||
|
@skip_win
|
||||||
|
Scenario: Successful upgrade with missing journal
|
||||||
|
Given we use the config "upgrade_from_195_with_missing_journal.json"
|
||||||
|
When we run "jrnl -ls" and enter "Y Y"
|
||||||
|
Then we should see the message "Journal 'missing' created"
|
||||||
|
Then we should see the message "We're all done here"
|
||||||
|
|
||||||
|
@skip_win
|
||||||
|
Scenario: Aborted upgrade with missing journal
|
||||||
|
Given we use the config "upgrade_from_195_with_missing_journal.json"
|
||||||
|
When we run "jrnl -ls" and enter "Y N"
|
||||||
|
Then we should see the message "jrnl NOT upgraded, exiting."
|
|
@ -11,10 +11,22 @@ import os
|
||||||
def backup(filename, binary=False):
|
def backup(filename, binary=False):
|
||||||
print(f" Created a backup at {filename}.backup", file=sys.stderr)
|
print(f" Created a backup at {filename}.backup", file=sys.stderr)
|
||||||
filename = os.path.expanduser(os.path.expandvars(filename))
|
filename = os.path.expanduser(os.path.expandvars(filename))
|
||||||
|
|
||||||
|
try:
|
||||||
with open(filename, "rb" if binary else "r") as original:
|
with open(filename, "rb" if binary else "r") as original:
|
||||||
contents = original.read()
|
contents = original.read()
|
||||||
|
|
||||||
with open(filename + ".backup", "wb" if binary else "w") as backup:
|
with open(filename + ".backup", "wb" if binary else "w") as backup:
|
||||||
backup.write(contents)
|
backup.write(contents)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"\nError: {filename} does not exist.")
|
||||||
|
try:
|
||||||
|
cont = util.yesno(f"\nCreate {filename}?", default=False)
|
||||||
|
if not cont:
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise UserAbort("jrnl NOT upgraded, exiting.")
|
||||||
|
|
||||||
|
|
||||||
def upgrade_jrnl_if_necessary(config_path):
|
def upgrade_jrnl_if_necessary(config_path):
|
||||||
|
@ -144,6 +156,7 @@ older versions of jrnl anymore.
|
||||||
j.write()
|
j.write()
|
||||||
|
|
||||||
print("\nUpgrading config...", file=sys.stderr)
|
print("\nUpgrading config...", file=sys.stderr)
|
||||||
|
|
||||||
backup(config_path)
|
backup(config_path)
|
||||||
|
|
||||||
print("\nWe're all done here and you can start enjoying jrnl 2.", file=sys.stderr)
|
print("\nWe're all done here and you can start enjoying jrnl 2.", file=sys.stderr)
|
||||||
|
|
Loading…
Add table
Reference in a new issue