Skip to content

bpo-33435: Fixed incorrect version detection of linux in some distrib… #6719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ def _parse_release_file(firstline):
id = l[1]
return '', version, id

def _prase_os_release(os_release_file):
params = ['NAME', 'VERSION_ID', 'ID']
vars_ = []
for line in os_release_file:
for param in params:
get_name = re.search(r'^' + param + '.*', line)
index = params.index(param)
if get_name != None:
params[index] = get_name.group(0)
for param in params:
param_split = param.split('=')
if len(param_split) > 1:
vars_.append(param_split[1])
else:
vars_.append('')
return vars_[0], vars_[1], vars_[2]

def linux_distribution(distname='', version='', id='',

supported_dists=_supported_dists,
Expand Down Expand Up @@ -333,16 +350,22 @@ def _linux_distribution(distname, version, id, supported_dists,
except OSError:
# Probably not a Unix system
return distname, version, id
etc.sort()
for file in etc:
m = _release_filename.match(file)
if m is not None:
_distname, dummy = m.groups()
if _distname in supported_dists:
distname = _distname
break
else:
return _dist_try_harder(distname, version, id)
try:
os_release_path = os.path.join(_UNIXCONFDIR, 'os-release')
with open(os_release_path, 'r', encoding='utf-8') as os_release_file:
distname, version, id = _prase_os_release(os_release_file)
return distname, version, id
except OSError:
etc.sort()
for file in etc:
m = _release_filename.match(file)
if m is not None:
_distname, dummy = m.groups()
if _distname in supported_dists:
distname = _distname
break
else:
return _dist_try_harder(distname, version, id)

# Read the first line
with open(os.path.join(_UNIXCONFDIR, file), 'r',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed incorrect version detection of linux in some distributions (Lib/platform.py method: linux_distribution()).
Now checked file os-release and if the file exists - parse the information from it, else used old method.