Skip to content

Commit

Permalink
bpo-27903: Fix ResourceWarning in platform.dist() (GH-10792)
Browse files Browse the repository at this point in the history
Fix ResourceWarning in platform.dist() and
platform.linux_distribution() on SuSE and Caldera OpenLinux.

Patch by Ville Skyttä.
(cherry picked from commit 7eeab87)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
  • Loading branch information
miss-islington and vstinner committed Nov 29, 2018
1 parent 2a852a2 commit cbf5767
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 19 additions & 17 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,29 @@ def _dist_try_harder(distname, version, id):
if os.path.exists('/var/adm/inst-log/info'):
# SuSE Linux stores distribution information in that file
distname = 'SuSE'
for line in open('/var/adm/inst-log/info'):
tv = line.split()
if len(tv) == 2:
tag, value = tv
else:
continue
if tag == 'MIN_DIST_VERSION':
version = value.strip()
elif tag == 'DIST_IDENT':
values = value.split('-')
id = values[2]
with open('/var/adm/inst-log/info') as f:
for line in f:
tv = line.split()
if len(tv) == 2:
tag, value = tv
else:
continue
if tag == 'MIN_DIST_VERSION':
version = value.strip()
elif tag == 'DIST_IDENT':
values = value.split('-')
id = values[2]
return distname, version, id

if os.path.exists('/etc/.installed'):
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
for line in open('/etc/.installed'):
pkg = line.split('-')
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
# XXX does Caldera support non Intel platforms ? If yes,
# where can we find the needed id ?
return 'OpenLinux', pkg[1], id
with open('/etc/.installed') as f:
for line in f:
pkg = line.split('-')
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
# XXX does Caldera support non Intel platforms ? If yes,
# where can we find the needed id ?
return 'OpenLinux', pkg[1], id

if os.path.isdir('/usr/lib/setup'):
# Check for slackware version tag file (thanks to Greg Andruk)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``ResourceWarning`` in :func:`platform.dist` on SuSE and Caldera
OpenLinux. Patch by Ville Skyttä.

0 comments on commit cbf5767

Please sign in to comment.