util/osrelease.py: Replaced string stripping with shlex.split()

- Replaced string stripping with `shlex.split()` to properly
handle values in the os-release file;
- This ensures cleaner and more accurate key-value assignments,
follwing a broader set of shell-like parsing rules;
- Add os-release file for Fedora CoreOS 40 for testing.

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
This commit is contained in:
Renata Ravanelli 2024-11-12 15:12:52 -03:00 committed by Dusty Mabe
parent f4b899873b
commit 07d4f6955d
2 changed files with 27 additions and 1 deletions

View file

@ -5,6 +5,7 @@ related documentation can be found in `os-release(5)`.
"""
import os
import shlex
# The default paths where os-release is located, as per os-release(5)
DEFAULT_PATHS = [
@ -33,7 +34,10 @@ def parse_files(*paths):
if line[0] == "#":
continue
key, value = line.split("=", 1)
osrelease[key] = value.strip('"')
split_value = shlex.split(value)
if not split_value or len(split_value) > 1:
raise ValueError(f"Key '{key}' has an empty value or more than one token: {value}")
osrelease[key] = split_value[0]
return osrelease

View file

@ -0,0 +1,22 @@
NAME="Fedora Linux"
VERSION="40.20241106.dev.0 (CoreOS)"
ID=fedora
VERSION_ID=40
VERSION_CODENAME=""
PLATFORM_ID="platform:f40"
PRETTY_NAME="Fedora CoreOS 40.20241106.dev.0"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:40"
HOME_URL="https://getfedora.org/coreos/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora-coreos/"
SUPPORT_URL="https://github.com/coreos/fedora-coreos-tracker/"
BUG_REPORT_URL="https://github.com/coreos/fedora-coreos-tracker/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=40
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=40
SUPPORT_END=2025-05-13
VARIANT="CoreOS"
VARIANT_ID=coreos
OSTREE_VERSION='40.20241106.dev.0'