mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Refactored install.py
This commit is contained in:
parent
f88eb8eb41
commit
8948c6b23b
2 changed files with 17 additions and 16 deletions
|
@ -32,6 +32,19 @@ default_config = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def update_config(config, config_path=os.path.expanduser("~/.jrnl_conf")):
|
||||||
|
"""Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
|
||||||
|
This essentially automatically ports jrnl installations if new config parameters are introduced in later
|
||||||
|
versions."""
|
||||||
|
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:
|
||||||
|
json.dump(config, f, indent=2)
|
||||||
|
print("[.jrnl_conf updated to newest version]")
|
||||||
|
|
||||||
|
|
||||||
def install_jrnl(config_path='~/.jrnl_config'):
|
def install_jrnl(config_path='~/.jrnl_config'):
|
||||||
def autocomplete(text, state):
|
def autocomplete(text, state):
|
||||||
expansions = glob.glob(os.path.expanduser(text)+'*')
|
expansions = glob.glob(os.path.expanduser(text)+'*')
|
||||||
|
|
20
jrnl/jrnl.py
20
jrnl/jrnl.py
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import Journal
|
import Journal
|
||||||
import exporters
|
import exporters
|
||||||
from install import *
|
import install
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -25,19 +25,7 @@ __author__ = 'Manuel Ebert, Stephan Gabler'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|
||||||
CONFIG_PATH = os.path.expanduser('~/.jrnl_config')
|
CONFIG_PATH = os.path.expanduser('~/.jrnl_config')
|
||||||
PYCRYPTO = module_exists("Crypto")
|
PYCRYPTO = install.module_exists("Crypto")
|
||||||
|
|
||||||
def update_config(config):
|
|
||||||
"""Checks if there are keys missing in a given config dict, and if so, updates the config file accordingly.
|
|
||||||
This essentially automatically ports jrnl installations if new config parameters are introduced in later
|
|
||||||
versions."""
|
|
||||||
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:
|
|
||||||
json.dump(config, f, indent=2)
|
|
||||||
print("[.jrnl_conf updated to newest version]")
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -140,11 +128,11 @@ def touch_journal(filename):
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
if not os.path.exists(CONFIG_PATH):
|
if not os.path.exists(CONFIG_PATH):
|
||||||
config = install_jrnl(CONFIG_PATH)
|
config = install.install_jrnl(CONFIG_PATH)
|
||||||
else:
|
else:
|
||||||
with open(CONFIG_PATH) as f:
|
with open(CONFIG_PATH) as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
update_config(config)
|
install.update_config(config, config_path=CONFIG_PATH)
|
||||||
|
|
||||||
# check if the configuration is supported by available modules
|
# check if the configuration is supported by available modules
|
||||||
if config['encrypt'] and not PYCRYPTO:
|
if config['encrypt'] and not PYCRYPTO:
|
||||||
|
|
Loading…
Add table
Reference in a new issue