From 6590045e5dd2fb0b1d7cdc047ae0c52fd4bb5276 Mon Sep 17 00:00:00 2001 From: Janosch Frank Date: Mon, 11 Jan 2016 16:17:32 +0100 Subject: scripts/kvm/kvm_stat: Replaced os.listdir with os.walk Os.walk gives back lists of directories and files, no need to filter directories from the list that listdir gives back. To make it better understandable a wrapper with docstring was introduced. Signed-off-by: Janosch Frank Message-Id: <1452525484-32309-3-git-send-email-frankja@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- scripts/kvm/kvm_stat | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index 3fadbfba93..63232767f3 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -26,7 +26,7 @@ from collections import defaultdict class DebugfsProvider(object): def __init__(self): self.base = '/sys/kernel/debug/kvm' - self._fields = os.listdir(self.base) + self._fields = walkdir(self.base)[2] def fields(self): return self._fields def select(self, fields): @@ -285,6 +285,15 @@ def detect_platform(): detect_platform() + +def walkdir(path): + """Returns os.walk() data for specified directory. + + As it is only a wrapper it returns the same 3-tuple of (dirpath, + dirnames, filenames). + """ + return next(os.walk(path)) + def invert(d): return dict((x[1], x[0]) for x in d.iteritems()) @@ -394,9 +403,7 @@ class Event(object): class TracepointProvider(object): def __init__(self): path = os.path.join(sys_tracing, 'events', 'kvm') - fields = [f - for f in os.listdir(path) - if os.path.isdir(os.path.join(path, f))] + fields = walkdir(path)[1] extra = [] for f in fields: if f in filters: -- cgit v1.2.3-55-g7522