diff options
author | Salvatore Bonaccorso <carnil@debian.org> | 2020-06-04 20:02:34 +0000 |
---|---|---|
committer | Salvatore Bonaccorso <carnil@debian.org> | 2020-06-04 20:02:34 +0000 |
commit | 12052760d6f12fd9ec6e3c42afe66449011b01cc (patch) | |
tree | 7048810cfb8bae504dcad525e825993ccb01bc48 /lib/python/config.py | |
parent | 5691f3044f636bfacb4b1ec5960a290d105cef59 (diff) | |
parent | 1b9c4741e886afe5f2bf6a4583d977bac225bdad (diff) |
Merge branch 'distro-config' into 'master'
Distro config reunification
See merge request security-tracker-team/security-tracker!48
Diffstat (limited to 'lib/python/config.py')
-rw-r--r-- | lib/python/config.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/python/config.py b/lib/python/config.py new file mode 100644 index 0000000000..c445dadb6c --- /dev/null +++ b/lib/python/config.py @@ -0,0 +1,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'] |