diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2012-05-01 18:46:52 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-05-01 18:46:52 -0500 |
commit | 15a0f3bf77cf60ae29484f0c0a26c679e4c688fd (patch) | |
tree | 40a5f82d8783ffa1435cf60084b0d6ccea646468 | |
parent | 174210fe70d34a1ac70b98c1e4412934cbee2061 (diff) | |
parent | e120d449e1b39ec508c297b963ce452628dd37c3 (diff) |
Merge remote-tracking branch 'stefanha/tracing' into staging
* stefanha/tracing:
configure: check for supported Python 2.x versions
tracetool: avoid pkgutil.iter_modules() Python 2.7 function
tracetool: avoid str.rpartition() Python 2.5 function
tracetool: use Python 2.4-compatible __import__() arguments
tracetool: use Python 2.4-compatible exception handling syntax
-rwxr-xr-x | configure | 7 | ||||
-rwxr-xr-x | scripts/tracetool.py | 4 | ||||
-rw-r--r-- | scripts/tracetool/__init__.py | 19 | ||||
-rw-r--r-- | scripts/tracetool/backend/__init__.py | 8 | ||||
-rw-r--r-- | scripts/tracetool/format/__init__.py | 8 |
5 files changed, 29 insertions, 17 deletions
@@ -1239,9 +1239,10 @@ fi # Note that if the Python conditional here evaluates True we will exit # with status 1 which is a shell 'false' value. -if ! "$python" -c 'import sys; sys.exit(sys.version_info[0] >= 3)'; then - echo "Python 2 required but '$python' is version 3 or better." - echo "Use --python=/path/to/python to specify a Python 2." +if ! "$python" -c 'import sys; sys.exit(sys.version_info < (2,4) or sys.version_info >= (3,))'; then + echo "Cannot use '$python', Python 2.4 or later is required." + echo "Note that Python 3 or later is not yet supported." + echo "Use --python=/path/to/python to specify a supported Python." exit 1 fi diff --git a/scripts/tracetool.py b/scripts/tracetool.py index cacfd99b62..c003cf69ed 100755 --- a/scripts/tracetool.py +++ b/scripts/tracetool.py @@ -70,7 +70,7 @@ def main(args): try: opts, args = getopt.getopt(args[1:], "", long_opts) - except getopt.GetoptError as err: + except getopt.GetoptError, err: error_opt(str(err)) check_backend = False @@ -131,7 +131,7 @@ def main(args): try: tracetool.generate(sys.stdin, arg_format, arg_backend, binary = binary, probe_prefix = probe_prefix) - except tracetool.TracetoolError as e: + except tracetool.TracetoolError, e: error_opt(str(e)) if __name__ == "__main__": diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 74fe21b226..175df08005 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -64,14 +64,17 @@ class Arguments: res = [] for arg in arg_str.split(","): arg = arg.strip() - parts = arg.split() - head, sep, tail = parts[-1].rpartition("*") - parts = parts[:-1] - if tail == "void": - assert len(parts) == 0 and sep == "" + if arg == 'void': continue - arg_type = " ".join(parts + [ " ".join([head, sep]).strip() ]).strip() - res.append((arg_type, tail)) + + if '*' in arg: + arg_type, identifier = arg.rsplit('*', 1) + arg_type += '*' + identifier = identifier.strip() + else: + arg_type, identifier = arg.rsplit(None, 1) + + res.append((arg_type, identifier)) return Arguments(res) def __iter__(self): @@ -204,7 +207,7 @@ def try_import(mod_name, attr_name = None, attr_default = None): object or attribute value. """ try: - module = __import__(mod_name, fromlist=["__package__"]) + module = __import__(mod_name, globals(), locals(), ["__package__"]) if attr_name is None: return True, module return True, getattr(module, str(attr_name), attr_default) diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py index 34b7ed8081..be43472f7b 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 0e4baf0e56..3c2a0d89e0 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 |