From c1bfd8b45125000c19a2e9d1b14a4656926968a3 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Sun, 15 Jul 2012 20:37:35 +0200 Subject: [PATCH] Refactored install.py --- jrnl/install.py | 13 +++++++++++++ jrnl/jrnl.py | 20 ++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/jrnl/install.py b/jrnl/install.py index 7341f8bb..deb8f88a 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -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 autocomplete(text, state): expansions = glob.glob(os.path.expanduser(text)+'*') diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 3b533a3e..6bfb8718 100755 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -9,7 +9,7 @@ import Journal import exporters -from install import * +import install import os import tempfile import subprocess @@ -25,19 +25,7 @@ __author__ = 'Manuel Ebert, Stephan Gabler' __license__ = 'MIT' CONFIG_PATH = os.path.expanduser('~/.jrnl_config') -PYCRYPTO = 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]") +PYCRYPTO = install.module_exists("Crypto") def parse_args(): parser = argparse.ArgumentParser() @@ -140,11 +128,11 @@ def touch_journal(filename): def cli(): if not os.path.exists(CONFIG_PATH): - config = install_jrnl(CONFIG_PATH) + config = install.install_jrnl(CONFIG_PATH) else: with open(CONFIG_PATH) as 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 if config['encrypt'] and not PYCRYPTO: