[et-mgmt-tools] [PATCH] virt-convert: fix Python 2.4 compatibility

Cole Robinson crobinso at redhat.com
Thu Jul 17 19:07:08 UTC 2008


john.levon at sun.com wrote:
> # HG changeset patch
> # User john.levon at sun.com
> # Date 1216320992 25200
> # Node ID cdab3fd5617c32955e16b9bf9cf1d121634746ec
> # Parent  cd648dc6a9492fe3b703e5ebc7f43d05bb03adeb
> virt-convert: fix Python 2.4 compatibility
> 
> Sadly, pkgutil.iter_modules() is new in Python 2.5, so the automatic
> module finding code won't work in 2.4. Add hard-coded fallbacks for Python 2.4
> and earlier.
> 
> Signed-off-by: John Levon <john.levon at sun.com>
> 
> diff --git a/virtconv/__init__.py b/virtconv/__init__.py
> --- a/virtconv/__init__.py
> +++ b/virtconv/__init__.py
> @@ -24,6 +24,15 @@
>  
>  parsers_path = [os.path.join(__path__[0], "parsers/")]
>  
> -for loader, name, ispkg in pkgutil.iter_modules(parsers_path):
> +# iter_modules is only in Python 2.5, sadly
> +parser_names = [ "vmx", "virtimage" ]
> +
> +if hasattr(pkgutil, "iter_modules"):
> +    print "here"

Probably didn't mean to include this line.

> +    parser_names = []
> +    for _, name, _ in pkgutil.iter_modules(parsers_path):

Please use something other than '_' here as previously
mentioned.

- Cole

> +        parser_names += [ name ]
> +
> +for name in parser_names:
>      filename, pathname, desc = imp.find_module(name, parsers_path)
>      imp.load_module(name, filename, pathname, desc)
> 




More information about the et-mgmt-tools mailing list