From 3374afa9506fdf38168834cc023d1b69c46d00fc Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Fri, 26 Jun 2009 12:17:10 +0100 Subject: [PATCH] Use ReadFile.splitlines() rather than readlines A few places in the code open a file "manually" rather than using our wrapper function, because they need an array with the lines. Combining the result of utils.ReadFile with splitlines() we get rid of the exceptions. Signed-off-by: Guido Trotter Reviewed-by: Iustin Pop --- lib/backend.py | 6 +----- lib/hypervisor/hv_base.py | 6 +----- tools/lvmstrap | 6 ++---- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 5bf45a9..b19b401 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -1490,11 +1490,7 @@ def _OSOndiskAPIVersion(name, os_dir): " a regular file" % os_dir) try: - f = open(api_file) - try: - api_versions = f.readlines() - finally: - f.close() + api_versions = utils.ReadFile(api_file).splitlines() except EnvironmentError, err: return False, ("Error while reading the API version file at %s: %s" % (api_file, _ErrnoOrStr(err))) diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 2370887..cdb7702 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -315,11 +315,7 @@ class BaseHypervisor(object): """ try: - fh = file("/proc/meminfo") - try: - data = fh.readlines() - finally: - fh.close() + data = utils.ReadFile("/proc/meminfo").splitlines() except EnvironmentError, err: raise errors.HypervisorError("Failed to list node info: %s" % (err,)) diff --git a/tools/lvmstrap b/tools/lvmstrap index 8af2f61..0a17a5f 100755 --- a/tools/lvmstrap +++ b/tools/lvmstrap @@ -44,7 +44,7 @@ import sys import optparse import time -from ganeti.utils import RunCmd +from ganeti.utils import RunCmd, ReadFile from ganeti import constants USAGE = ("\tlvmstrap diskinfo\n" @@ -424,9 +424,7 @@ def GetMountInfo(): a mountpoint: device number dictionary """ - f = open("/proc/mounts", "r") - mountlines = f.readlines() - f.close() + mountlines = ReadFile("/proc/mounts").splitlines() mounts = {} for line in mountlines: device, mountpoint, fstype, rest = line.split(None, 3) -- 1.7.10.4