From 38cab0187de480b2d4cfafa32e285adc2e305b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Mon, 6 May 2024 16:56:54 +0200 Subject: [PATCH] Remove deprecated pkg-resources references QubesOS/qubes-issues#9195 --- .../agent/source/plugins/manage_rpm_macro.py | 18 ++++++++++-------- .../agent/source/plugins/updatesproxy_fix.py | 1 - vmupdate/agent/source/utils.py | 6 ++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/vmupdate/agent/source/plugins/manage_rpm_macro.py b/vmupdate/agent/source/plugins/manage_rpm_macro.py index a0806693..dee42eb6 100644 --- a/vmupdate/agent/source/plugins/manage_rpm_macro.py +++ b/vmupdate/agent/source/plugins/manage_rpm_macro.py @@ -21,8 +21,6 @@ import os -import pkg_resources - def manage_rpm_macro(os_data, log, **kwargs): """ @@ -30,12 +28,16 @@ def manage_rpm_macro(os_data, log, **kwargs): """ if os_data["os_family"] == "RedHat": rpm_macro = "/usr/lib/rpm/macros.d/macros.qubes" - if (os_data["id"] == "fedora" - and os_data["release"] < pkg_resources.parse_version("33")): - log.info("Old fedora version detected.") - with open(rpm_macro, "w") as file: - file.write("# CVE-2021-20271 mitigation\n" - "%_pkgverify_level all") + if os_data["id"] == "fedora": + try: + version = int(os_data["release"].split(".")[0]) + except ValueError: + version = 99 # fedora changed its version + if version < 33: + log.info("Old fedora version detected.") + with open(rpm_macro, "w") as file: + file.write("# CVE-2021-20271 mitigation\n" + "%_pkgverify_level all") else: if os.path.exists(rpm_macro): os.remove(rpm_macro) diff --git a/vmupdate/agent/source/plugins/updatesproxy_fix.py b/vmupdate/agent/source/plugins/updatesproxy_fix.py index 6a4f2b8e..74f387a6 100644 --- a/vmupdate/agent/source/plugins/updatesproxy_fix.py +++ b/vmupdate/agent/source/plugins/updatesproxy_fix.py @@ -22,7 +22,6 @@ import os import pathlib -import pkg_resources def updatesproxy_fix(os_data, log, **kwargs): diff --git a/vmupdate/agent/source/utils.py b/vmupdate/agent/source/utils.py index d267b450..d486954d 100644 --- a/vmupdate/agent/source/utils.py +++ b/vmupdate/agent/source/utils.py @@ -23,8 +23,6 @@ import ast from typing import Optional, Dict, Any -import pkg_resources - def get_os_data(logger: Optional = None) -> Dict[str, Any]: """ @@ -34,7 +32,7 @@ def get_os_data(logger: Optional = None) -> Dict[str, Any]: id: "linux" or a lower-case string identifying the operating system, name: "Linux" or a string identifying the operating system, codename (optional): an operating system release code name, - release (optional): packaging.version.Version, + release (optional): version string, os_family: "Unknown", "RedHat", "Debian", "ArchLinux". """ data = {} @@ -49,7 +47,7 @@ def get_os_data(logger: Optional = None) -> Dict[str, Any]: data["name"] = os_release.get("NAME", "Linux").strip() if "VERSION_ID" in os_release: release = os_release["VERSION_ID"] - data["release"] = pkg_resources.parse_version(release) + data["release"] = release if "VERSION_CODENAME" in os_release: data["codename"] = os_release["VERSION_CODENAME"]