From patchwork Mon Apr 30 11:06:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 155838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B8A7B6EE6 for ; Mon, 30 Apr 2012 21:08:03 +1000 (EST) Received: from localhost ([::1]:36189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOoSW-0005V2-Vi for incoming@patchwork.ozlabs.org; Mon, 30 Apr 2012 07:08:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOoSK-0005Fy-Ep for qemu-devel@nongnu.org; Mon, 30 Apr 2012 07:07:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SOoSI-0004lm-GA for qemu-devel@nongnu.org; Mon, 30 Apr 2012 07:07:47 -0400 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:54166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SOoSI-0004lM-7E for qemu-devel@nongnu.org; Mon, 30 Apr 2012 07:07:46 -0400 Received: from /spool/local by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 30 Apr 2012 12:07:42 +0100 Received: from d06nrmr1507.portsmouth.uk.ibm.com (9.149.38.233) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 30 Apr 2012 12:07:17 +0100 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q3UB7HBh2605140 for ; Mon, 30 Apr 2012 12:07:17 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q3UB7GJo019640 for ; Mon, 30 Apr 2012 05:07:16 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.241]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q3UB7FZf019617; Mon, 30 Apr 2012 05:07:16 -0600 From: Stefan Hajnoczi To: Date: Mon, 30 Apr 2012 12:06:32 +0100 Message-Id: <1335783992-25149-6-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1335783992-25149-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1335783992-25149-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12043011-4966-0000-0000-0000022C2AEC X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.106 Cc: Peter Maydell , Anthony Liguori , Stefan Hajnoczi , Erik Rull , Andreas Faerber , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Subject: [Qemu-devel] [PATCH v2 5/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The pkgutil.iter_modules() function provides a way to enumerate child modules. Unfortunately it's missing in Python <2.7 so we must implement similar behavior ourselves. Signed-off-by: Stefan Hajnoczi Reviewed-by: LluĂ­s Vilanova --- scripts/tracetool/backend/__init__.py | 8 ++++++-- scripts/tracetool/format/__init__.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py index 34b7ed8..be43472 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -37,7 +37,7 @@ __maintainer__ = "Stefan Hajnoczi" __email__ = "stefanha@linux.vnet.ibm.com" -import pkgutil +import os import tracetool @@ -45,7 +45,11 @@ import tracetool def get_list(): """Get a list of (name, description) pairs.""" res = [("nop", "Tracing disabled.")] - for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__): + modnames = [] + for filename in os.listdir(tracetool.backend.__path__[0]): + if filename.endswith('.py') and filename != '__init__.py': + modnames.append(filename.rsplit('.', 1)[0]) + for modname in modnames: module = tracetool.try_import("tracetool.backend." + modname) # just in case; should never fail unless non-module files are put there diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py index 0e4baf0..3c2a0d8 100644 --- a/scripts/tracetool/format/__init__.py +++ b/scripts/tracetool/format/__init__.py @@ -41,7 +41,7 @@ __maintainer__ = "Stefan Hajnoczi" __email__ = "stefanha@linux.vnet.ibm.com" -import pkgutil +import os import tracetool @@ -49,7 +49,11 @@ import tracetool def get_list(): """Get a list of (name, description) pairs.""" res = [] - for _, modname, _ in pkgutil.iter_modules(tracetool.format.__path__): + modnames = [] + for filename in os.listdir(tracetool.format.__path__[0]): + if filename.endswith('.py') and filename != '__init__.py': + modnames.append(filename.rsplit('.', 1)[0]) + for modname in modnames: module = tracetool.try_import("tracetool.format." + modname) # just in case; should never fail unless non-module files are put there