summaryrefslogtreecommitdiffstats
path: root/lib/python/config.py
blob: c445dadb6ce5a38844d65b3a071d81f524b09ff6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# config.py -- methods to read global configuration from data/config.json
# Copyright (C) 2019 Emilio Pozuelo Monfort <pochu@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# TODO: the OrderedDict use can be dropped once we use Python 3 (>= 3.7)
from collections import OrderedDict
import json
import os

_config = None

def get_config():
    global _config
    if not _config:
        d = os.path.dirname(os.path.abspath(__file__))

        with open(d + '/../../data/config.json') as f:
            config = json.load(f, object_pairs_hook=OrderedDict)

        _config = config['distributions']

    return _config

def get_supported_releases():
    config = get_config()

    return [d for d in config.keys() if 'release' in config[d]]

def get_all_releases():
    config = get_config()

    return config.keys()

def get_release_codename(release, suffix=''):
    config = get_config()

    for r in config.keys():
        if 'release' in config[r] and config[r]['release'] == release:
            return r + suffix

    return None

def get_release_alias(codename):
    config = get_config()

    return config[codename]['release']

© 2014-2024 Faster IT GmbH | imprint | privacy policy