All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes
@ 2012-05-01 15:40 Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 1/5] tracetool: use Python 2.4-compatible exception handling syntax Stefan Hajnoczi
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

The new Python tracetool implementation works great but does not run on older
Python installations.  This series takes us back to the happy days of Python
2.4, which was released in 2004.

As a result tracetool should now work again on Mac OS X v10.5.8, OpenIndiana
oi_151a, Solaris 10 U9, and Red Hat Enterprise Linux 5.

I added a new patch which should make --list-backends work on Python <2.7 now.

Thanks for everyone's help testing on these platforms.

v2:
 * Use nicer version check Python expression [Lluís]
 * Avoid pkgutil.iter_modules() [Andreas]

v3:
 * Fix missing sys.exit() in configure check [Lluís]

Stefan Hajnoczi (5):
  tracetool: use Python 2.4-compatible exception handling syntax
  tracetool: use Python 2.4-compatible __import__() arguments
  tracetool: avoid str.rpartition() Python 2.5 function
  tracetool: avoid pkgutil.iter_modules() Python 2.7 function
  configure: check for supported Python 2.x versions

 configure                             |    7 ++++---
 scripts/tracetool.py                  |    4 ++--
 scripts/tracetool/__init__.py         |   19 +++++++++++--------
 scripts/tracetool/backend/__init__.py |    8 ++++++--
 scripts/tracetool/format/__init__.py  |    8 ++++++--
 5 files changed, 29 insertions(+), 17 deletions(-)

-- 
1.7.10

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 1/5] tracetool: use Python 2.4-compatible exception handling syntax
  2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
@ 2012-05-01 15:40 ` Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 2/5] tracetool: use Python 2.4-compatible __import__() arguments Stefan Hajnoczi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

The newer "except <exception-type> as <exception>:" syntax is not
supported by Python 2.4, we need to use "except <exception-type>,
<exception>:".

Tested all trace backends with Python 2.4.

Reported-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 scripts/tracetool.py |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index cacfd99..c003cf6 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__":
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 2/5] tracetool: use Python 2.4-compatible __import__() arguments
  2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 1/5] tracetool: use Python 2.4-compatible exception handling syntax Stefan Hajnoczi
@ 2012-05-01 15:40 ` Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 3/5] tracetool: avoid str.rpartition() Python 2.5 function Stefan Hajnoczi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

In Python 2.5 keyword arguments were added to __import__().  Avoid using
them to achieve Python 2.4 compatibility.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 scripts/tracetool/__init__.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 74fe21b..49858c9 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -204,7 +204,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)
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 3/5] tracetool: avoid str.rpartition() Python 2.5 function
  2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 1/5] tracetool: use Python 2.4-compatible exception handling syntax Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 2/5] tracetool: use Python 2.4-compatible __import__() arguments Stefan Hajnoczi
@ 2012-05-01 15:40 ` Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 4/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions Stefan Hajnoczi
  4 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

The str.rpartition() function is related to str.split() and is used for
splitting strings.  It was introduced in Python 2.5 and therefore cannot
be used in tracetool as Python 2.4 compatibility is required.

Replace the code using str.rsplit().

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 scripts/tracetool/__init__.py |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 49858c9..175df08 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):
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 4/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function
  2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 3/5] tracetool: avoid str.rpartition() Python 2.5 function Stefan Hajnoczi
@ 2012-05-01 15:40 ` Stefan Hajnoczi
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions Stefan Hajnoczi
  4 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

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>
---
 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__      = "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 0e4baf0..3c2a0d8 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
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions
  2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
                   ` (3 preceding siblings ...)
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 4/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function Stefan Hajnoczi
@ 2012-05-01 15:40 ` Stefan Hajnoczi
  2012-05-01 16:00   ` Lluís Vilanova
  4 siblings, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2012-05-01 15:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Anthony Liguori, Stefan Hajnoczi, Erik Rull,
	Andreas Faerber, Lluís Vilanova

The tracetool code requires Python 2.4, which was released in 2004.
Check for a supported Python version so we can give a clear error
message.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 configure |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 25697bb..ccffd87 100755
--- a/configure
+++ b/configure
@@ -1247,9 +1247,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
 
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions
  2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions Stefan Hajnoczi
@ 2012-05-01 16:00   ` Lluís Vilanova
  0 siblings, 0 replies; 7+ messages in thread
From: Lluís Vilanova @ 2012-05-01 16:00 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: Peter Maydell, Anthony Liguori, qemu-devel, Andreas Faerber, Erik Rull

Stefan Hajnoczi writes:

> The tracetool code requires Python 2.4, which was released in 2004.
> Check for a supported Python version so we can give a clear error
> message.

> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>

> ---
>  configure |    7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

> diff --git a/configure b/configure
> index 25697bb..ccffd87 100755
> --- a/configure
> +++ b/configure
> @@ -1247,9 +1247,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
 
> -- 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-01 16:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-01 15:40 [Qemu-devel] [PATCH v3 0/5] tracetool: Python 2.4 compatibility fixes Stefan Hajnoczi
2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 1/5] tracetool: use Python 2.4-compatible exception handling syntax Stefan Hajnoczi
2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 2/5] tracetool: use Python 2.4-compatible __import__() arguments Stefan Hajnoczi
2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 3/5] tracetool: avoid str.rpartition() Python 2.5 function Stefan Hajnoczi
2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 4/5] tracetool: avoid pkgutil.iter_modules() Python 2.7 function Stefan Hajnoczi
2012-05-01 15:40 ` [Qemu-devel] [PATCH v3 5/5] configure: check for supported Python 2.x versions Stefan Hajnoczi
2012-05-01 16:00   ` Lluís Vilanova

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.