Dear Michael, et al,
/usr/bin/unattended-upgrade runs three lsb_release subprocesses to
determine distro info.
It would be better to use Python's platform.freedesktop_os_release()
instead for the following reasons:
* Uses Python module instead of external command
* Does not use the "global" statement
* Implementation has 12 fewer lines
* Faster
Untested patch below.
Thank you!
Daniel Lewart
Urbana, Illinois
diff -ru a/unattended-upgrade b/unattended-upgrade
--- a/unattended-upgrade 2025-08-27 05:10:50.000000000 -0500
+++ b/unattended-upgrade 2025-09-18 00:00:00.000000000 -0500
@@ -47,8 +47,9 @@
import locale
import logging
import logging.handlers
-import re
import os
+import platform
+import re
import select
import signal
import socket
@@ -112,24 +113,11 @@
USERS = "/usr/bin/users"
-# no py3 lsb_release in debian :/
-DISTRO_CODENAME = "" # type: str
-DISTRO_DESC = "" # type: str
-DISTRO_ID = "" # type: str
-
-
-def init_distro_info():
- global DISTRO_CODENAME, DISTRO_DESC, DISTRO_ID
- DISTRO_CODENAME = subprocess.check_output(
- ["lsb_release", "-c", "-s"], universal_newlines=True).strip()
- DISTRO_DESC = subprocess.check_output(
- ["lsb_release", "-d", "-s"], universal_newlines=True).strip()
- DISTRO_ID = subprocess.check_output(
- ["lsb_release", "-i", "-s"], universal_newlines=True).strip()
-
-
# init global distro info
-init_distro_info()
+info = platform.freedesktop_os_release()
+DISTRO_CODENAME = info["VERSION_CODENAME"] # type: str
+DISTRO_DESC = info["PRETTY_NAME"] # type: str
+DISTRO_ID = str.capitalize(info["ID"]) # type: str
# Number of days before release of devel where we enable unattended