diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-11-29 11:53:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-29 11:53:19 (GMT) |
commit | cbf57674e257617977b35c016e861a52b5f65359 (patch) | |
tree | e76af31d42333ab1b9b6edc880fd7f55b945fea3 /Lib/platform.py | |
parent | 2a852a2b122cf9545909234cdc8fca564dc8f805 (diff) | |
download | cpython-cbf57674e257617977b35c016e861a52b5f65359.zip cpython-cbf57674e257617977b35c016e861a52b5f65359.tar.gz cpython-cbf57674e257617977b35c016e861a52b5f65359.tar.bz2 |
bpo-27903: Fix ResourceWarning in platform.dist() (GH-10792)
Fix ResourceWarning in platform.dist() and
platform.linux_distribution() on SuSE and Caldera OpenLinux.
Patch by Ville Skyttä.
(cherry picked from commit 7eeab87263b831adbe617a4af7ec5b5d9296962a)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-x | Lib/platform.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index 4205abd..fa56d41 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -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) |