mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 22:16:13 +02:00
Use PyXDG to save config and journal in XDG dirs
This change also hides the CONFIG_PATH state information entirely within the install module. Therefore, the cli module does not have to care about checking existence of files and paths.
This commit is contained in:
parent
fca3d131bd
commit
afae3d16a7
4 changed files with 39 additions and 25 deletions
14
jrnl/cli.py
14
jrnl/cli.py
|
@ -18,8 +18,6 @@ import os
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
xdg_config = os.environ.get('XDG_CONFIG_HOME')
|
||||
CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config')
|
||||
PYCRYPTO = install.module_exists("Crypto")
|
||||
|
||||
|
||||
|
@ -122,11 +120,7 @@ def run(manual_args=None):
|
|||
print(util.py2encode(version_str))
|
||||
sys.exit(0)
|
||||
|
||||
if not os.path.exists(CONFIG_PATH):
|
||||
config = install.install_jrnl(CONFIG_PATH)
|
||||
else:
|
||||
config = util.load_and_fix_json(CONFIG_PATH)
|
||||
install.upgrade_config(config, CONFIG_PATH)
|
||||
config = install.install_jrnl()
|
||||
|
||||
if args.ls:
|
||||
print(util.py2encode(list_journals(config)))
|
||||
|
@ -235,18 +229,18 @@ def run(manual_args=None):
|
|||
# Not encrypting to a separate file: update config!
|
||||
if not args.encrypt:
|
||||
update_config(original_config, {"encrypt": True}, journal_name, force_local=True)
|
||||
install.save_config(original_config, CONFIG_PATH)
|
||||
install.save_config(original_config)
|
||||
|
||||
elif args.decrypt is not False:
|
||||
decrypt(journal, filename=args.decrypt)
|
||||
# Not decrypting to a separate file: update config!
|
||||
if not args.decrypt:
|
||||
update_config(original_config, {"encrypt": False}, journal_name, force_local=True)
|
||||
install.save_config(original_config, CONFIG_PATH)
|
||||
install.save_config(original_config)
|
||||
|
||||
elif args.edit:
|
||||
if not config['editor']:
|
||||
util.prompt("[You need to specify an editor in {0} to use the --edit function.]".format(CONFIG_PATH))
|
||||
util.prompt("[You need to specify an editor in {0} to use the --edit function.]".format(install.CONFIG_FILE_PATH))
|
||||
sys.exit(1)
|
||||
other_entries = [e for e in old_entries if e not in journal.entries]
|
||||
# Edit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue