config.py 701 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
import configparser
import os

_parser = None


def _get_parser():
    global _parser

    if not _parser:
11
12
13
        path = os.environ.get('AUR_CONFIG', '/etc/aurweb/config')
        defaults = os.environ.get('AUR_CONFIG_DEFAULTS', path + '.defaults')

14
        _parser = configparser.RawConfigParser()
15
16
17
        if os.path.isfile(defaults):
            with open(defaults) as f:
                _parser.read_file(f)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
        _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)