From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 4/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function
Date: Tue, 1 May 2012 20:28:37 +0100 [thread overview]
Message-ID: <1335900518-6730-5-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1335900518-6730-1-git-send-email-stefanha@linux.vnet.ibm.com>
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 <stefanha@linux.vnet.ibm.com>
Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
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
--
1.7.10
next prev parent reply other threads:[~2012-05-01 19:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-01 19:28 [Qemu-devel] [PULL 0/5] Tracing patches for 1.1 Stefan Hajnoczi
2012-05-01 19:28 ` [Qemu-devel] [PATCH 1/5] tracetool: use Python 2.4-compatible exception handling syntax Stefan Hajnoczi
2012-05-01 19:28 ` [Qemu-devel] [PATCH 2/5] tracetool: use Python 2.4-compatible __import__() arguments Stefan Hajnoczi
2012-05-01 19:28 ` [Qemu-devel] [PATCH 3/5] tracetool: avoid str.rpartition() Python 2.5 function Stefan Hajnoczi
2012-05-01 19:28 ` Stefan Hajnoczi [this message]
2012-05-01 19:28 ` [Qemu-devel] [PATCH 5/5] configure: check for supported Python 2.x versions Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1335900518-6730-5-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).