diff options
author | Adam Stokes <adam.stokes@canonical.com> | 2012-02-21 10:32:38 +0000 |
---|---|---|
committer | Adam Stokes <adam.stokes@canonical.com> | 2012-02-21 10:32:38 +0000 |
commit | 1264037635b9c23b4256507773f0e178dc758dfb (patch) | |
tree | b722ee72d2dfdd70a5cf388d1b966cd7a38b8e75 | |
parent | b47e98dd2115b44d2bbd540870129ca33e865e3c (diff) | |
download | sos-1264037635b9c23b4256507773f0e178dc758dfb.tar.gz |
UbuntuPolicy: Make sure reading of lsb-release always closes
Signed-off-by: Adam Stokes <adam.stokes@canonical.com>
-rw-r--r-- | sos/policies/ubuntu.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py index c841b22b..d0ecae0f 100644 --- a/sos/policies/ubuntu.py +++ b/sos/policies/ubuntu.py @@ -2,6 +2,7 @@ from sos import _sos as _ from sos.plugins import UbuntuPlugin, IndependentPlugin from sos.policies.debian import DebianPolicy, DebianPackageManager from sos.utilities import shell_out +from __future__ import with_statement import os @@ -19,10 +20,8 @@ class UbuntuPolicy(DebianPolicy): It returns True or False.""" if os.path.isfile('/etc/lsb-release'): try: - fp = open('/etc/lsb-release', 'r') - if "Ubuntu" in fp.read(): - fp.close() - return True + with open('/etc/lsb-release', 'r') as fp: + return "Ubuntu" in fp.read() except: return False return False |