mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
make update of new settings a bit more general and remove some whitespace
* config.update(default_config) does not work, would overwrite all values
This commit is contained in:
parent
530514c7ac
commit
e8435a0445
1 changed files with 11 additions and 7 deletions
18
jrnl.py
18
jrnl.py
|
@ -155,7 +155,7 @@ class Journal:
|
||||||
self.config['password'] = None # This password doesn't work.
|
self.config['password'] = None # This password doesn't work.
|
||||||
if attempts < 3:
|
if attempts < 3:
|
||||||
print("Wrong password, try again.")
|
print("Wrong password, try again.")
|
||||||
else:
|
else:
|
||||||
print("Extremely wrong password.")
|
print("Extremely wrong password.")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
journal = decrypted
|
journal = decrypted
|
||||||
|
@ -230,7 +230,7 @@ class Journal:
|
||||||
filename = filename or self.config['journal']
|
filename = filename or self.config['journal']
|
||||||
journal = os.linesep.join([str(e) for e in self.entries])
|
journal = os.linesep.join([str(e) for e in self.entries])
|
||||||
if self.config['encrypt']:
|
if self.config['encrypt']:
|
||||||
journal = self._encrypt(journal)
|
journal = self._encrypt(journal)
|
||||||
with open(filename, 'w') as journal_file:
|
with open(filename, 'w') as journal_file:
|
||||||
journal_file.write(journal)
|
journal_file.write(journal)
|
||||||
|
|
||||||
|
@ -341,24 +341,28 @@ def setup():
|
||||||
default_config['highlight'] = False
|
default_config['highlight'] = False
|
||||||
|
|
||||||
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
open(default_config['journal'], 'a').close() # Touch to make sure it's there
|
||||||
|
|
||||||
# Write config to ~/.jrnl_conf
|
# Write config to ~/.jrnl_conf
|
||||||
with open(CONFIG_PATH, 'w') as f:
|
with open(CONFIG_PATH, 'w') as f:
|
||||||
json.dump(default_config, f, indent=2)
|
json.dump(default_config, f, indent=2)
|
||||||
config = default_config
|
config = default_config
|
||||||
if password:
|
if password:
|
||||||
config['password'] = password
|
config['password'] = password
|
||||||
return config
|
return config
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if not os.path.exists(CONFIG_PATH):
|
if not os.path.exists(CONFIG_PATH):
|
||||||
config = setup()
|
config = setup()
|
||||||
else:
|
else:
|
||||||
with open(CONFIG_PATH) as f:
|
with open(CONFIG_PATH) as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
if not 'highlight' in config:
|
|
||||||
config['highlight'] = False
|
# update config file with settings introduced in a later version
|
||||||
|
missing_keys = set(default_config).difference(config)
|
||||||
|
if missing_keys:
|
||||||
|
for key in missing_keys:
|
||||||
|
config[key] = default_config[key]
|
||||||
with open(CONFIG_PATH, 'w') as f:
|
with open(CONFIG_PATH, 'w') as f:
|
||||||
json.dump(config, f, indent=2)
|
json.dump(config, f, indent=2)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue