Skip to content

Commit

Permalink
Merge pull request #1 from aequitas/modules
Browse files Browse the repository at this point in the history
Allow configuration of app modules
  • Loading branch information
Johan Bloemberg committed Feb 9, 2016
2 parents bc06b65 + c70796c commit 9036cef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions rcfile.py
Expand Up @@ -6,7 +6,7 @@
import os
import logging

__version__ = "0.1.1"
__version__ = "0.1.4"
__author__ = "Johan Bloemberg"
__license__ = "MIT"

Expand Down Expand Up @@ -36,7 +36,7 @@ def get_environment(appname):
return dict([(k.replace(prefix, '').lower(), v) for k, v in vars])


def get_config(appname, config_file):
def get_config(appname, module_name, config_file):
home = expanduser('~')
files = [
join('/etc', appname, 'config'),
Expand All @@ -51,15 +51,15 @@ def get_config(appname, config_file):

config = ConfigParser.ConfigParser()
read = config.read(files)
log.debug('files read: %s' % read)
log.debug('files read: %s' % read)

if not config.has_section(appname):
if not config.has_section(module_name):
return {}

return dict(config.items(appname))
return dict(config.items(module_name))


def rcfile(appname, args={}, strip_dashes=True):
def rcfile(appname, args={}, strip_dashes=True, module_name=None):
"""
Read environment variables and config files and return them merged with predefined list of arguments.
Expand Down Expand Up @@ -93,6 +93,9 @@ def rcfile(appname, args={}, strip_dashes=True):

environ = get_environment(appname)

config = get_config(appname, args.get('config', ''))
if not module_name:
module_name = appname

config = get_config(appname, module_name, args.get('config', ''))

return merge(merge(args, config), environ)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -32,7 +32,7 @@ def read(fname):

setup(
name='rcfile',
version="0.1.2",
version="0.1.4",
description='Configuration file loader',
long_description=read("README.rst"),
author='Johan Bloemberg',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,py33
envlist = py26,py27,py34
[testenv]
deps=
nose
Expand Down

0 comments on commit 9036cef

Please sign in to comment.