From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44148) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706k-0003HG-9n for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a706g-0003ly-7A for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:02 -0500 Received: from e06smtp06.uk.ibm.com ([195.75.94.102]:43528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706f-0003lQ-UX for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:13:58 -0500 Received: from localhost by e06smtp06.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Dec 2015 12:13:56 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 48EEC17D8066 for ; Thu, 10 Dec 2015 12:14:25 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBACDqib3015098 for ; Thu, 10 Dec 2015 12:13:52 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBACDqpq024994 for ; Thu, 10 Dec 2015 05:13:52 -0700 From: Janosch Frank Date: Thu, 10 Dec 2015 13:12:32 +0100 Message-Id: <1449749584-23214-3-git-send-email-frankja@linux.vnet.ibm.com> In-Reply-To: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 02/34] scripts/kvm/kvm_stat: Replaced os.listdir with os.walk List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com, frankja@linux.vnet.ibm.com 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. --- 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 3fadbfb..6323276 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: -- 2.3.0