From 5ff90c0210be6b9b48f5cc269d2450e85a958ec0 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Mon, 16 Mar 2020 14:33:35 +0100 Subject: [PATCH] Use lsb_release fallback code if "import distro" fails With python 3.8, the standard python "platform" module doesn't provide the "dist()" function any more. The "distro" module is used instead. However, not all distributions ship the "distro" module by default. Catch the resulting exception, and use the already existing fallback code to determine the distribution using lsb_release. --- base/password.py | 8 ++++++-- installer/core_install.py | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/base/password.py b/base/password.py index cc91ac7..4352f9d 100644 --- a/base/password.py +++ b/base/password.py @@ -84,8 +84,12 @@ def get_distro_name(): try: os_name = platform.dist()[0] except AttributeError: - import distro - os_name = distro.linux_distribution()[0] + try: + import distro + os_name = distro.linux_distribution()[0] + except (ImportError, AttributeError): + # Use fallback code below + pass if not os_name: name = os.popen('lsb_release -i | cut -f 2') diff --git a/installer/core_install.py b/installer/core_install.py index eaecdc6..8c6b67f 100644 --- a/installer/core_install.py +++ b/installer/core_install.py @@ -644,9 +644,13 @@ class CoreInstall(object): name = platform.dist()[0].lower() ver = platform.dist()[1] except AttributeError: - import distro - name = distro.linux_distribution()[0].lower() - ver = distro.linux_distribution()[1] + try: + import distro + name = distro.linux_distribution()[0].lower() + ver = distro.linux_distribution()[1] + except (ImportError, AttributeError): + # Use fallback code below + pass if not name: found = False -- 2.25.1