summaryrefslogtreecommitdiff
path: root/meta/classes/buildstats.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-07 13:55:58 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-05-09 14:04:18 +0100
commitec74285bd2108f12f33fc8ac0dc1d124ab48be21 (patch)
tree14c483feea17bf945aa52777b5b70d3f31ee8803 /meta/classes/buildstats.bbclass
parentb010501cd089e649a68f683be0cf4d0aac90fbe3 (diff)
downloadopenembedded-core-ec74285bd2108f12f33fc8ac0dc1d124ab48be21.tar.gz
openembedded-core-ec74285bd2108f12f33fc8ac0dc1d124ab48be21.tar.bz2
openembedded-core-ec74285bd2108f12f33fc8ac0dc1d124ab48be21.zip
buildstats: Update to ensure files are closed
python3 doesn't like files being left open. This updates the code style to ensure file are closed. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/buildstats.bbclass')
-rw-r--r--meta/classes/buildstats.bbclass31
1 files changed, 16 insertions, 15 deletions
diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass
index 6fd13a8602..453c50b968 100644
--- a/meta/classes/buildstats.bbclass
+++ b/meta/classes/buildstats.bbclass
@@ -12,12 +12,14 @@ DEVFILE = "${BUILDSTATS_BASE}/.device"
################################################################################
def get_process_cputime(pid):
- fields = open("/proc/%d/stat" % pid, "r").readline().rstrip().split()
+ with open("/proc/%d/stat" % pid, "r") as f:
+ fields = f.readline().rstrip().split()
# 13: utime, 14: stime, 15: cutime, 16: cstime
return sum(int(field) for field in fields[13:16])
def get_cputime():
- fields = open("/proc/stat", "r").readline().rstrip().split()[1:]
+ with open("/proc/stat", "r") as f:
+ fields = f.readline().rstrip().split()[1:]
return sum(int(field) for field in fields)
def set_bn(e):
@@ -26,14 +28,12 @@ def set_bn(e):
os.remove(e.data.getVar('BNFILE', True))
except:
pass
- file = open(e.data.getVar('BNFILE', True), "w")
- file.write(os.path.join(bn, e.data.getVar('BUILDNAME', True)))
- file.close()
+ with open(e.data.getVar('BNFILE', True), "w") as f:
+ f.write(os.path.join(bn, e.data.getVar('BUILDNAME', True)))
def get_bn(e):
- file = open(e.data.getVar('BNFILE', True))
- bn = file.readline()
- file.close()
+ with open(e.data.getVar('BNFILE', True)) as f:
+ bn = f.readline()
return bn
def set_device(e):
@@ -63,9 +63,10 @@ def set_device(e):
############################################################################
rdev="NoLogicalDevice"
try:
- for line in open("/proc/diskstats", "r"):
- if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
- rdev=line.split()[2]
+ with open("/proc/diskstats", "r") as f:
+ for line in f:
+ if majordev == int(line.split()[0]) and minordev == int(line.split()[1]):
+ rdev=line.split()[2]
except:
pass
file = open(e.data.getVar('DEVFILE', True), "w")
@@ -85,9 +86,10 @@ def get_diskstats(dev):
############################################################################
DSTAT_KEYS = ['ReadsComp', 'ReadsMerged', 'SectRead', 'TimeReads', 'WritesComp', 'SectWrite', 'TimeWrite', 'IOinProgress', 'TimeIO', 'WTimeIO']
try:
- for x in open("/proc/diskstats", "r"):
- if dev in x:
- diskstats_val = x.rstrip().split()[4:]
+ with open("/proc/diskstats", "r") as f:
+ for x in f:
+ if dev in x:
+ diskstats_val = x.rstrip().split()[4:]
except IOError as e:
return
diskstats = dict(itertools.izip(DSTAT_KEYS, diskstats_val))
@@ -274,7 +276,6 @@ python run_buildstats () {
file = open(build_status,"a")
file.write(e.data.expand("Failed at: ${PF} at task: %s \n" % e.task))
file.close()
-
}
addhandler run_buildstats