]> git.ipfire.org Git - pakfire.git/commitdiff
util: Add a simple function to read the distro name
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 12:14:53 +0000 (12:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 12:14:53 +0000 (12:14 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/hub.py
src/pakfire/util.py

index d8108e4f768d19316e8f347295a75f36c313c7df..95d2ad002fd5164e068df0452a2fd612516eed86 100644 (file)
@@ -30,7 +30,7 @@ import tornado.httpclient
 import urllib.parse
 
 from . import _pakfire
-from .distro import Distribution
+from . import util
 from .constants import *
 from .i18n import _
 
@@ -234,9 +234,6 @@ class Hub(object):
                """
                log.info(_("Sending builder information to hub..."))
 
-               # Fetch distribution information
-               distro = Distribution()
-
                # Fetch processor information
                cpu = cpuinfo.get_cpu_info()
 
@@ -248,7 +245,7 @@ class Hub(object):
 
                        # Pakfire + OS
                        "pakfire_version" : PAKFIRE_VERSION,
-                       "os_name"         : distro.pretty_name,
+                       "os_name"         : util.get_distro_name(),
                }
 
                # Send request
index 4db3ad6d7fca6ba78921900f5dce1c4908513f4a..74d257ac3e656331c6b2e580b363712337ca0090 100644 (file)
 ###############################################################################
 
 import os
+import platform
 import shutil
 
+def get_distro_name():
+       """
+               Returns the distro name of the host
+       """
+       try:
+               release = platform.freedesktop_os_release()
+       except AttributeError:
+               release = _read_os_release()
+
+       return release.get("PRETTY_NAME") or release.get("NAME")
+
+def _read_os_release():
+       """
+               This is a simple implementation to read /etc/os-release and /var/lib/os-release
+       """
+       for file in ("/etc/os-release", "/var/lib/os-release"):
+               try:
+                       with open(file, "r") as f:
+                               release = {}
+
+                               for line in f:
+                                       key, delim, value = line.partition("=")
+
+                                       release[key] = value
+
+                               return release
+               except FileNotFoundError:
+                       pass
+
+               raise OSError("Could not find os-release")
+
 def rm(path, *args, **kargs):
        """
                version of shutil.rmtree that ignores no-such-file-or-directory errors,