From e03167e476c73da4c94e324d8654a16dc536fff6 Mon Sep 17 00:00:00 2001 From: Jacob Sayles Date: Mon, 1 Jun 2020 10:18:54 -0700 Subject: [PATCH 1/3] Use the distro package in dist_name if it exists or fall back to platform. Fixes #314 --- modoboa_installer/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modoboa_installer/utils.py b/modoboa_installer/utils.py index 08732df..d95eeae 100644 --- a/modoboa_installer/utils.py +++ b/modoboa_installer/utils.py @@ -4,7 +4,6 @@ import contextlib import datetime import glob import os -import platform import random import shutil import string @@ -76,7 +75,14 @@ def exec_cmd(cmd, sudo_user=None, pinput=None, login=True, **kwargs): def dist_name(): """Try to guess the distribution name.""" - name, version, _id = platform.linux_distribution() + try: + # Python 3.7 and up way + import distro + name, version, _id = distro.linux_distribution() + except ModuleNotFoundError as e: + # Python 3.6 and down way + import platform + name, version, _id = platform.linux_distribution() return "unknown" if not name else name.lower() From 174dde340508b6db890f77d571f91cb343c5441b Mon Sep 17 00:00:00 2001 From: Jacob Sayles Date: Mon, 1 Jun 2020 10:22:53 -0700 Subject: [PATCH 2/3] Fixed reference to python versions --- modoboa_installer/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modoboa_installer/utils.py b/modoboa_installer/utils.py index d95eeae..e0327ce 100644 --- a/modoboa_installer/utils.py +++ b/modoboa_installer/utils.py @@ -76,11 +76,11 @@ def exec_cmd(cmd, sudo_user=None, pinput=None, login=True, **kwargs): def dist_name(): """Try to guess the distribution name.""" try: - # Python 3.7 and up way + # Python 3.8 and up way import distro name, version, _id = distro.linux_distribution() except ModuleNotFoundError as e: - # Python 3.6 and down way + # Python 3.7 and down way import platform name, version, _id = platform.linux_distribution() return "unknown" if not name else name.lower() From 07515508d70accf36c3b35b0d7df9605fb403154 Mon Sep 17 00:00:00 2001 From: Jacob Sayles Date: Mon, 1 Jun 2020 10:46:09 -0700 Subject: [PATCH 3/3] switched to ImportError over ModuleNotFoundError for python 3.4 and below --- modoboa_installer/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modoboa_installer/utils.py b/modoboa_installer/utils.py index e0327ce..4ed7916 100644 --- a/modoboa_installer/utils.py +++ b/modoboa_installer/utils.py @@ -79,7 +79,7 @@ def dist_name(): # Python 3.8 and up way import distro name, version, _id = distro.linux_distribution() - except ModuleNotFoundError as e: + except ImportError as e: # Python 3.7 and down way import platform name, version, _id = platform.linux_distribution()