From 0dedcd867d90b7cf6603c632393c8f0ba005cc01 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Wed, 18 Nov 2015 14:25:37 +0100 Subject: [PATCH] Changed config keys --- .config | 6 ++---- solar/solar/config.py | 4 ++-- solar/solar/dblayer/__init__.py | 25 +++++++++++++------------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.config b/.config index 1aaf8b4d..424b2169 100644 --- a/.config +++ b/.config @@ -2,10 +2,8 @@ dblayer: riak redis: host: localhost port: '6379' -riak: +solar_db: + mode: riak host: localhost port: '8087' protocol: pbc -sqlite: - backend: memory - location: ':memory:' diff --git a/solar/solar/config.py b/solar/solar/config.py index 87284557..ab40b990 100644 --- a/solar/solar/config.py +++ b/solar/solar/config.py @@ -6,8 +6,7 @@ CWD = os.getcwd() C = Bunch() C.redis = Bunch(port='6379', host='10.0.0.2') -C.riak = Bunch(port='8087', host='10.0.0.2', protocol='pbc') -C.sqlite = Bunch(backend='memory', location=':memory:') +C.solar_db = Bunch(mode='riak', port='8087', host='10.0.0.2', protocol='pbc') C.dblayer = 'riak' @@ -52,6 +51,7 @@ def from_configs(): config[path[-1]] = vals _lookup_vals(_setter, C) + def from_env(): def _setter(config, path): env_key = '_'.join(path).upper() diff --git a/solar/solar/dblayer/__init__.py b/solar/solar/dblayer/__init__.py index 09e0e7d6..a7827b0d 100644 --- a/solar/solar/dblayer/__init__.py +++ b/solar/solar/dblayer/__init__.py @@ -2,27 +2,28 @@ from solar.dblayer.model import ModelMeta from solar.dblayer.riak_client import RiakClient from solar.config import C -if C.dblayer == 'sqlite': + +if C.solar_db.mode == 'sqlite': from solar.dblayer.sql_client import SqlClient - if C.sqlite.backend == 'memory': - client = SqlClient(C.sqlite.location, threadlocals=False, autocommit=False) - elif C.sqlite.backend == 'file': - client = SqlClient(C.sqlite.location, threadlocals=True, + if C.solar_db.backend == 'memory': + client = SqlClient(C.solar_db.location, threadlocals=False, autocommit=False) + elif C.solar_db.backend == 'file': + client = SqlClient(C.solar_db.location, threadlocals=True, autocommit=False, pragmas=(('journal_mode', 'WAL'), ('synchronous', 'NORMAL'))) else: - raise Exception('Unknown sqlite backend %s', C.sqlite.backend) + raise Exception('Unknown sqlite backend %s', C.solar_db.backend) -elif C.dblayer == 'riak': +elif C.solar_db.mode == 'riak': from solar.dblayer.riak_client import RiakClient - if C.riak.protocol == 'pbc': + if C.solar_db.protocol == 'pbc': client = RiakClient( - protocol=C.riak.protocol, host=C.riak.host, pb_port=C.riak.port) - elif C.riak.protocol == 'http': + protocol=C.solar_db.protocol, host=C.solar_db.host, pb_port=C.solar_db.port) + elif C.solar_db.protocol == 'http': client = RiakClient( - protocol=C.riak.protocol, host=C.riak.host, http_port=C.riak.port) + protocol=C.solar_db.protocol, host=C.solar_db.host, http_port=C.solar_db.port) else: - raise Exception('Unknown riak protocol %s', C.riak.protocol) + raise Exception('Unknown riak protocol %s', C.solar_db.protocol) else: raise Exception('Unknown dblayer backend %s', C.dblayer)