From 8185dc37e0c03b62268c025e7b59bb4e8644f6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 13 Jul 2019 00:36:49 +0200 Subject: [PATCH] Read os-release instead of using platform.linux_distribution() The function was removed in https://bugs.python.org/issue1322 and cannot be used in python3.8. There are replacements outside of the stdlib, but it doesn't seem worth it it add a dependency on another module. Instead, a simple parser for os-release is implemented. os-release is present on all distros from the last few years and PRETTY_NAME gives a reliable display name of the distro without any heuristics. --- blosc/toplevel.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/blosc/toplevel.py b/blosc/toplevel.py index 04ad9f0217..94cf4af910 100644 --- a/blosc/toplevel.py +++ b/blosc/toplevel.py @@ -800,6 +800,20 @@ def load_tests(loader, tests, pattern): tests.addTests(doctest.DocTestSuite()) return tests +def os_release_pretty_name(): + for p in ('/etc/os-release', '/usr/lib/os-release'): + try: + f = open(p, 'rt') + for line in f: + name, _, value = line.rstrip().partition('=') + if name == 'PRETTY_NAME': + if len(value) >= 2 and value[0] in '"\'' and value[0] == value[-1]: + value = value[1:-1] + return value + except IOError: + pass + else: + return None def print_versions(): """Print all the versions of software that python-blosc relies on.""" @@ -815,7 +829,9 @@ def print_versions(): (sysname, nodename, release, version, machine, processor) = platform.uname() print("Platform: %s-%s-%s (%s)" % (sysname, release, machine, version)) if sysname == "Linux": - print("Linux dist: %s" % " ".join(platform.linux_distribution()[:-1])) + distro = os_release_pretty_name() + if distro: + print("Linux dist:", distro) if not processor: processor = "not recognized" print("Processor: %s" % processor)