From 47899605d19e6b28b36444a1ca1a2809363e00c2 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Wed, 27 Nov 2019 13:45:27 +0100 Subject: config.py: add python module to read config.json --- lib/python/config.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/python/config.py (limited to 'lib') diff --git a/lib/python/config.py b/lib/python/config.py new file mode 100644 index 0000000000..61f633ee28 --- /dev/null +++ b/lib/python/config.py @@ -0,0 +1,52 @@ +# config.py -- methods to read global configuration from data/config.json +# Copyright (C) 2019 Emilio Pozuelo Monfort +# +# 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 + +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) + + _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_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'] -- cgit v1.2.3