Commit 425f5bb7 authored by Thomas Gambier's avatar Thomas Gambier

slapgrid: replace platform.linux_distribution() with distro.linux_distribution()

platform.linux_distribution() is deprecated since Python3.5 and it's
removed altogether in Python 3.8.

This more or less reverts 75b2d79c.

We don't need anymore the patch for Ubuntu as it is correctly supported
in distro module.
parent ba0239a9
Pipeline #20286 failed with stage
in 0 seconds
...@@ -77,6 +77,7 @@ setup(name=name, ...@@ -77,6 +77,7 @@ setup(name=name,
'jsonschema', 'jsonschema',
'PyYAML', 'PyYAML',
'uritemplate', # used by hateoas navigator 'uritemplate', # used by hateoas navigator
'distro',
'subprocess32; python_version<"3"', 'subprocess32; python_version<"3"',
'enum34; python_version<"3"', 'enum34; python_version<"3"',
'ipaddress; python_version<"3"', # used by whitelistfirewall 'ipaddress; python_version<"3"', # used by whitelistfirewall
......
...@@ -33,20 +33,11 @@ Provides helper functions to check if two binary caches are compatible. ...@@ -33,20 +33,11 @@ Provides helper functions to check if two binary caches are compatible.
os_matches(...): os_matches(...):
returns True if the arguments reference compatible platforms. returns True if the arguments reference compatible platforms.
patched_linux_distribution(...):
a patched version of platform.linux_distribution()
this is the same function provided with the python package in Debian and Ubuntu:
see http://bugs.python.org/issue9514
otherwise, Ubuntu will always be reported as an unstable Debian, regardless of the version.
distribution_tuple() distribution_tuple()
returns a (distname, version, id) tuple under linux or cygwin returns a (distname, version, id) tuple under linux
""" """
import platform import distro
import re
def _debianize(os_): def _debianize(os_):
...@@ -65,38 +56,5 @@ def os_matches(os1, os2): ...@@ -65,38 +56,5 @@ def os_matches(os1, os2):
return _debianize(os1) == _debianize(os2) return _debianize(os1) == _debianize(os2)
_distributor_id_file_re = re.compile(r"(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
_release_file_re = re.compile(r"(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
_codename_file_re = re.compile(r"(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I)
def patched_linux_distribution(distname='', version='', id='',
supported_dists=platform._supported_dists,
full_distribution_name=1):
# check for the Debian/Ubuntu /etc/lsb-release file first, needed so
# that the distribution doesn't get identified as Debian.
try:
etclsbrel = open("/etc/lsb-release", "rU")
for line in etclsbrel:
m = _distributor_id_file_re.search(line)
if m:
_u_distname = m.group(1).strip()
m = _release_file_re.search(line)
if m:
_u_version = m.group(1).strip()
m = _codename_file_re.search(line)
if m:
_u_id = m.group(1).strip()
if _u_distname and _u_version:
return (_u_distname, _u_version, _u_id)
except (EnvironmentError, UnboundLocalError):
pass
return platform.linux_distribution(distname, version, id, supported_dists, full_distribution_name)
def distribution_tuple(): def distribution_tuple():
if platform.system().startswith('CYGWIN_'): return distro.linux_distribution(full_distribution_name=False)
return (platform.system(), platform.platform(), '')
else:
return patched_linux_distribution()
...@@ -15,7 +15,6 @@ from __future__ import print_function ...@@ -15,7 +15,6 @@ from __future__ import print_function
import ast import ast
import json import json
import platform
import shutil import shutil
import subprocess import subprocess
import traceback import traceback
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment