Received: from eggs.gnu.org ([208.118.235.92]:53896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPD7Z-0000lt-9i for qemu-devel@nongnu.org; Tue, 01 May 2012 09:28:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPD7W-0006Sc-Su for qemu-devel@nongnu.org; Tue, 01 May 2012 09:28:00 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:56303 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPD7W-0006SP-I0 for qemu-devel@nongnu.org; Tue, 01 May 2012 09:27:58 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <1335783992-25149-1-git-send-email-stefanha@linux.vnet.ibm.com> <1335783992-25149-6-git-send-email-stefanha@linux.vnet.ibm.com> Date: Tue, 01 May 2012 15:27:53 +0200 In-Reply-To: <1335783992-25149-6-git-send-email-stefanha@linux.vnet.ibm.com> (Stefan Hajnoczi's message of "Mon, 30 Apr 2012 12:06:32 +0100") Message-ID: <87wr4wjajq.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 5/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Peter Maydell , Erik Rull , Anthony Liguori , qemu-devel@nongnu.org, Andreas Faerber Stefan Hajnoczi writes: > 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=C3=ADs 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/ba= ckend/__init__.py > index 34b7ed8..be43472 100644 > --- a/scripts/tracetool/backend/__init__.py > +++ b/scripts/tracetool/backend/__init__.py > @@ -37,7 +37,7 @@ __maintainer__ =3D "Stefan Hajnoczi" > __email__ =3D "stefanha@linux.vnet.ibm.com" =20 =20 > -import pkgutil > +import os =20 > import tracetool =20 > @@ -45,7 +45,11 @@ import tracetool > def get_list(): > """Get a list of (name, description) pairs.""" > res =3D [("nop", "Tracing disabled.")] > - for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__= ): > + modnames =3D [] > + for filename in os.listdir(tracetool.backend.__path__[0]): > + if filename.endswith('.py') and filename !=3D '__init__.py': > + modnames.append(filename.rsplit('.', 1)[0]) > + for modname in modnames: > module =3D tracetool.try_import("tracetool.backend." + modname) =20 > # just in case; should never fail unless non-module files are pu= t there > diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/for= mat/__init__.py > index 0e4baf0..3c2a0d8 100644 > --- a/scripts/tracetool/format/__init__.py > +++ b/scripts/tracetool/format/__init__.py > @@ -41,7 +41,7 @@ __maintainer__ =3D "Stefan Hajnoczi" > __email__ =3D "stefanha@linux.vnet.ibm.com" =20 =20 > -import pkgutil > +import os =20 > import tracetool =20 > @@ -49,7 +49,11 @@ import tracetool > def get_list(): > """Get a list of (name, description) pairs.""" > res =3D [] > - for _, modname, _ in pkgutil.iter_modules(tracetool.format.__path__): > + modnames =3D [] > + for filename in os.listdir(tracetool.format.__path__[0]): > + if filename.endswith('.py') and filename !=3D '__init__.py': > + modnames.append(filename.rsplit('.', 1)[0]) > + for modname in modnames: > module =3D tracetool.try_import("tracetool.format." + modname) =20 > # just in case; should never fail unless non-module files are pu= t there > --=20 > 1.7.10 --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth