Commit 3374afa9 authored by Guido Trotter's avatar Guido Trotter

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: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 7ead9575
......@@ -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)))
......
......@@ -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,))
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment