config.py 1.1 KB
Newer Older
1
2
3
import configparser
import os

4
5
6
7
8
# Publicly visible version of aurweb. This is used to display
# aurweb versioning in the footer and must be maintained.
# Todo: Make this dynamic/automated.
AURWEB_VERSION = "v5.0.0"

9
10
11
12
13
14
15
_parser = None


def _get_parser():
    global _parser

    if not _parser:
16
17
18
        path = os.environ.get('AUR_CONFIG', '/etc/aurweb/config')
        defaults = os.environ.get('AUR_CONFIG_DEFAULTS', path + '.defaults')

19
        _parser = configparser.RawConfigParser()
20
21
22
        if os.path.isfile(defaults):
            with open(defaults) as f:
                _parser.read_file(f)
23
24
25
26
27
        _parser.read(path)

    return _parser


Kevin Morris's avatar
Kevin Morris committed
28
29
30
31
32
33
34
def rehash():
    """ Globally rehash the configuration parser. """
    global _parser
    _parser = None
    _get_parser()


35
36
37
38
def get_with_fallback(section, option, fallback):
    return _get_parser().get(section, option, fallback=fallback)


39
40
41
42
43
44
45
46
47
48
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)