# HG changeset patch # User Dennis Fink # Date 2015-10-14 22:36:29 # Node ID fe1223a12bbaf3dc693ae7fa2ceff8a20fb6c1d8 # Parent 065f9ae807a14a72ac2f9522c794934f0478adb8 Open the config file correctly diff --git a/ennstatus/cli/commands/config.py b/ennstatus/cli/commands/config.py --- a/ennstatus/cli/commands/config.py +++ b/ennstatus/cli/commands/config.py @@ -40,7 +40,9 @@ def server(): @click.pass_obj def add(obj, name, ips, password): - config = json.load(obj['config_file']) + with obj['config_file'].open() as f: + config = json.load(f) + name = name.lower() ips = [ip.strip() for ip in ips.split(',')] @@ -61,7 +63,7 @@ def add(obj, name, ips, password): 'PASSWORD': password } - with open(obj['config_file'], mode='w', encoding='utf-8') as f: + with obj['config_file'].open(mode='w', encoding='utf-8') as f: json.dump(config, f, indent=4, sort_keys=True) @@ -70,7 +72,8 @@ def add(obj, name, ips, password): @click.pass_obj def delete(obj, name): - config = json.load(obj['config_file']) + with obj['config_file'].open() as f: + config = json.load(f) name = name.lower() try: @@ -78,5 +81,5 @@ def delete(obj, name): except KeyError: raise SystemExit('{} does not exists!'.format(name)) - with open(obj['config_file'], mode='w', encoding='utf-8') as f: + with obj['config_file'].open(mode='w', encoding='utf-8') as f: json.dump(config, f, indent=4, sort_keys=True)