Skip to content
New issue

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

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

Already on GitHub? # to your account

Guess common *-release files if /etc not readable. #175

Merged
merged 9 commits into from
Apr 1, 2017
19 changes: 14 additions & 5 deletions distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,11 +983,20 @@ def _get_distro_release_info(self):
distro_info['id'] = match.group(1)
return distro_info
else:
basenames = os.listdir(_UNIXCONFDIR)
# We sort for repeatability in cases where there are multiple
# distro specific files; e.g. CentOS, Oracle, Enterprise all
# containing `redhat-release` on top of their own.
basenames.sort()
try:
basenames = os.listdir(_UNIXCONFDIR)
# We sort for repeatability in cases where there are multiple
# distro specific files; e.g. CentOS, Oracle, Enterprise all
# containing `redhat-release` on top of their own.
basenames.sort()
except OSError:
# This may occur when /etc is not readable but we can't be
# sure about the *-release files. Check common entries of
# /etc for information. If they turn out to not be there the
# error is handled in `_parse_distro_release_file()`.
basenames = ['os-release', 'redhat-release', 'system-release',
'base-release', 'fedora-release',
'centos-release', 'SuSE-release']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This order is different from the one you'd get with basenames.sort(), you may want to move the basenames.sort() outside of the try block to preserve equivilant results for with/without permissions on /etc/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I could just sort it myself. :) I'll do that.

for basename in basenames:
if basename in _DISTRO_RELEASE_IGNORE_BASENAMES:
continue
Expand Down