Source code for libka.ubuntu_info
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# pylint: disable=line-too-long
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
# pylint: enable=line-too-long
############################################################################
# Copyright © 2016-2019 José Manuel Santamaría Lema <panfaust@gmail.com> #
# #
# 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 module provides various utilities to operate with ubuntu release codenames and versions.
"""
from libka.ka_data_utils import read_json_data_file
_UBUNTU_VERSION_MAP = None
_UBUNTU_NAME_MAP = None
def _load_ubuntu_version_map():
global _UBUNTU_VERSION_MAP #pylint: disable=global-statement
_UBUNTU_VERSION_MAP = read_json_data_file("ubuntu-release-info.json")["releases"]
def _load_ubuntu_name_map():
if _UBUNTU_VERSION_MAP is None:
_load_ubuntu_name_map()
global _UBUNTU_NAME_MAP #pylint: disable=global-statement
_UBUNTU_NAME_MAP = dict((v, k) for k, v in _UBUNTU_VERSION_MAP.items())
[docs]
def ubuntu_dist_version_from_name(dist_name):
"""
Returns the Ubuntu distribution version from its codename.
Example: `ubuntu_dist_version_from_name("eoan")` should return `"19.10"`.
"""
if _UBUNTU_VERSION_MAP is None:
_load_ubuntu_version_map()
return _UBUNTU_VERSION_MAP[dist_name]
[docs]
def ubuntu_dist_name_from_version(version):
"""
Returns the Ubuntu distribution codename from version.
Example: `ubuntu_dist_name_from_version("19.10")` should return `"eoan"`
"""
if _UBUNTU_NAME_MAP is None:
_load_ubuntu_name_map()
return _UBUNTU_NAME_MAP[version]
[docs]
def previous_ubuntu_version(version):
"""
Returns the previous Ubuntu version.
Example: `previous_ubuntu_version("19.10")` should return `"19.04"`.
"""
year, month = version.split('.')
if month == '10':
month = '04'
else:
year = str(int(year) - 1)
month = '10'
version = year + '.' + month
return version