mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-06 08:25:45 +00:00
tracetool: avoid pkgutil.iter_modules() Python 2.7 function
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>
This commit is contained in:
parent
b3ef0ade57
commit
9943e0ec38
@ -37,7 +37,7 @@ __maintainer__ = "Stefan Hajnoczi"
|
|||||||
__email__ = "stefanha@linux.vnet.ibm.com"
|
__email__ = "stefanha@linux.vnet.ibm.com"
|
||||||
|
|
||||||
|
|
||||||
import pkgutil
|
import os
|
||||||
|
|
||||||
import tracetool
|
import tracetool
|
||||||
|
|
||||||
@ -45,7 +45,11 @@ import tracetool
|
|||||||
def get_list():
|
def get_list():
|
||||||
"""Get a list of (name, description) pairs."""
|
"""Get a list of (name, description) pairs."""
|
||||||
res = [("nop", "Tracing disabled.")]
|
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)
|
module = tracetool.try_import("tracetool.backend." + modname)
|
||||||
|
|
||||||
# just in case; should never fail unless non-module files are put there
|
# just in case; should never fail unless non-module files are put there
|
||||||
|
@ -41,7 +41,7 @@ __maintainer__ = "Stefan Hajnoczi"
|
|||||||
__email__ = "stefanha@linux.vnet.ibm.com"
|
__email__ = "stefanha@linux.vnet.ibm.com"
|
||||||
|
|
||||||
|
|
||||||
import pkgutil
|
import os
|
||||||
|
|
||||||
import tracetool
|
import tracetool
|
||||||
|
|
||||||
@ -49,7 +49,11 @@ import tracetool
|
|||||||
def get_list():
|
def get_list():
|
||||||
"""Get a list of (name, description) pairs."""
|
"""Get a list of (name, description) pairs."""
|
||||||
res = []
|
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)
|
module = tracetool.try_import("tracetool.format." + modname)
|
||||||
|
|
||||||
# just in case; should never fail unless non-module files are put there
|
# just in case; should never fail unless non-module files are put there
|
||||||
|
Loading…
Reference in New Issue
Block a user