git-interface: Factor out configuration file parsing

Add a new module that automatically locates the configuration file and
provides methods to obtain the values of configuration options.

Use the new module instead of ConfigParser everywhere.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2016-08-03 20:21:40 +02:00
parent 2915abb9d3
commit 2f5f5583be
5 changed files with 32 additions and 18 deletions

27
git-interface/config.py Normal file
View file

@ -0,0 +1,27 @@
import configparser
import os
_parser = None
def _get_parser():
global _parser
if not _parser:
_parser = configparser.RawConfigParser()
path = os.path.dirname(os.path.realpath(__file__)) + "/../conf/config"
_parser.read(path)
return _parser
def get(section, option):
return _get_parser().get(section, option)
def getboolean(section, option):
return _get_parser().getboolean(section, option)
def getint(section, option):
return _get_parser().getint(section, option)