qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 5/5] tracetool: avoid pkgutil.iter_modules()


From: Lluís Vilanova
Subject: Re: [Qemu-devel] [PATCH v2 5/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function
Date: Tue, 01 May 2012 15:27:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

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 <address@hidden>

Reviewed-by: Lluís Vilanova <address@hidden>

> ---
>  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__      = "address@hidden"
 
 
> -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__      = "address@hidden"
 
 
> -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


-- 
 "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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]