diff mbox

tracetool: use Python 2.5-compatible exception handling syntax

Message ID 1335346956-5625-1-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi April 25, 2012, 9:42 a.m. UTC
The newer "except <exception-type> as <exception>:" syntax is not
supported by Python 2.5, we need to use "except <exception-type>,
<exception>:".

Tested all trace backends with Python 2.5.6.

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

Comments

Lluís Vilanova April 25, 2012, 12:09 p.m. UTC | #1
Stefan Hajnoczi writes:

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

> Tested all trace backends with Python 2.5.6.

> 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
Andreas Färber April 25, 2012, 1:35 p.m. UTC | #2
Am 25.04.2012 11:42, schrieb Stefan Hajnoczi:
> The newer "except <exception-type> as <exception>:" syntax is not
> supported by Python 2.5, we need to use "except <exception-type>,
> <exception>:".
> 
> Tested all trace backends with Python 2.5.6.
> 
> Reported-by: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Lightly

Tested-by: Andreas Färber <andreas.faerber@web.de>

Works with:
2.5.1 (Mac OS X v10.5.8),
2.6.1 (Mac OS X v10.6.8) and
2.6.4 (OpenIndiana oi_151a).

Thanks a lot!

However, it still breaks with different errors on Python 2.3.3 and 2.4.6
(Solaris 10 U9).

$ python scripts/tracetool.py --list-backends
Traceback (most recent call last):
  File "scritps/tracetool.py", line 19, in ?
    from tracetool import error_writem out
  File "/export/home/andreas/QEMU/qemu/scripts/tracetool/__init__.py",
line 55
    @staticmethod
    ^

$ python2.4 scripts/tracetool.py --list-backends
Traceback (most recent call last):
  File "scripts/tracetool.py", line 138, in ?
    main(sys.argv)
  File "scripts/tracetool.py", line 93, in main
    backends = tracetool.backend.get_list()
  File
"/export/home/andreas/QEMU/qemu/scripts/tracetool/backend/__init__.py",
line 48, in get_list
    for _, modname, _ in pkgutil.iter_modules(tracetool.backend.__path__):
AttributeError: 'module' object has no attribute 'iter_modules'

Seems like Python is not the ultimate better-than-POSIX compatibility
solution after all... :-/

Andreas

> ---
>  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__":
Stefan Hajnoczi April 25, 2012, 3:29 p.m. UTC | #3
On Wed, Apr 25, 2012 at 2:35 PM, Andreas Färber <andreas.faerber@web.de> wrote:
> Am 25.04.2012 11:42, schrieb Stefan Hajnoczi:
>> The newer "except <exception-type> as <exception>:" syntax is not
>> supported by Python 2.5, we need to use "except <exception-type>,
>> <exception>:".
>>
>> Tested all trace backends with Python 2.5.6.
>>
>> Reported-by: Andreas Färber <afaerber@suse.de>
>> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> Lightly
>
> Tested-by: Andreas Färber <andreas.faerber@web.de>
>
> Works with:
> 2.5.1 (Mac OS X v10.5.8),
> 2.6.1 (Mac OS X v10.6.8) and
> 2.6.4 (OpenIndiana oi_151a).
>
> Thanks a lot!
>
> However, it still breaks with different errors on Python 2.3.3 and 2.4.6
> (Solaris 10 U9).

Solaris releases tend to be supported for a very long time.  I don't
think we should restrict ourselves to glib, python, and other
dependencies from the Solaris 10 era (actually Solaris 9 is still
supported too!).

We need to draw the line somewhere.  Python 2.5 was released on
September 19, 2006.  It's available for Mac ppc and Solaris.

Here is the latest blastwave Python package which supposedly works for
Solaris 8+ on i386:

http://www.blastwave.org/jir/pkgcontents.ftd?software=python&style=brief&state=5&arch=i386

Stefan
Erik Rull April 26, 2012, 5:02 p.m. UTC | #4
On April 25, 2012 at 11:42 AM Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
wrote:

> The newer "except <exception-type> as <exception>:" syntax is not
> supported by Python 2.5, we need to use "except <exception-type>,
> <exception>:".
>
> Tested all trace backends with Python 2.5.6.
>
> Reported-by: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  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
>
>


Hi all,

is this related to the error message when calling configure:
./configure --prefix= --target-list=x86_64-softmmu --disable-vnc-png
--disable-vnc-jpeg --disable-vnc-tls --disable-vnc-sasl --audio-card-list=
--audio-drv-list= --enable-sdl --disable-xen --disable-brlapi
--disable-bluez --disable-nptl --disable-curl --disable-guest-agent
--disable-guest-base --disable-werror --disable-attr


Error: invalid trace backend
Please choose a supported trace backend.


When trying to press tab after typing --tra appending to the line above, I
get:

  File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
    except getopt.GetoptError as err:
                               ^
SyntaxError: invalid syntax
  File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
    except getopt.GetoptError as err:
                               ^
SyntaxError: invalid syntax

Any ideas?
My Debian 4.0 has Python 2.4.4.

Best regards,

Erik
Erik Rull April 27, 2012, 7:27 a.m. UTC | #5
On April 26, 2012 at 7:02 PM Erik Rull <erik.rull@rdsoftware.de> wrote:

>
>
>
> On April 25, 2012 at 11:42 AM Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com>
> wrote:
>
> > The newer "except <exception-type> as <exception>:" syntax is not
> > supported by Python 2.5, we need to use "except <exception-type>,
> > <exception>:".
> >
> > Tested all trace backends with Python 2.5.6.
> >
> > Reported-by: Andreas Färber <afaerber@suse.de>
> > Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> > ---
> >  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
> >
> >
>
>
> Hi all,
>
> is this related to the error message when calling configure:
> ./configure --prefix= --target-list=x86_64-softmmu --disable-vnc-png
> --disable-vnc-jpeg --disable-vnc-tls --disable-vnc-sasl
--audio-card-list=
> --audio-drv-list= --enable-sdl --disable-xen --disable-brlapi
> --disable-bluez --disable-nptl --disable-curl --disable-guest-agent
> --disable-guest-base --disable-werror --disable-attr
>
>
> Error: invalid trace backend
> Please choose a supported trace backend.
>
>
> When trying to press tab after typing --tra appending to the line above,
I
> get:
>
>   File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
>     except getopt.GetoptError as err:
>                                ^
> SyntaxError: invalid syntax
>   File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
>     except getopt.GetoptError as err:
>                                ^
> SyntaxError: invalid syntax
>
> Any ideas?
> My Debian 4.0 has Python 2.4.4.
>
> Best regards,
>
> Erik
>

Hi all,

Finally I managed installing python 2.5 on my debian box - but it's not
better:

python -V reports now python 2.5

The error message when pressing <tab> is still the same:

And now?

Best regards,

Erik
Stefan Hajnoczi April 27, 2012, 10 a.m. UTC | #6
On Thu, Apr 26, 2012 at 07:02:39PM +0200, Erik Rull wrote:
> is this related to the error message when calling configure:
> ./configure --prefix= --target-list=x86_64-softmmu --disable-vnc-png
> --disable-vnc-jpeg --disable-vnc-tls --disable-vnc-sasl --audio-card-list=
> --audio-drv-list= --enable-sdl --disable-xen --disable-brlapi
> --disable-bluez --disable-nptl --disable-curl --disable-guest-agent
> --disable-guest-base --disable-werror --disable-attr
> 
> 
> Error: invalid trace backend
> Please choose a supported trace backend.
> 
> 
> When trying to press tab after typing --tra appending to the line above, I
> get:
> 
>   File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
>     except getopt.GetoptError as err:
>                                ^
> SyntaxError: invalid syntax
>   File "/home/erik/qemu-test/qemu/scripts/tracetool.py", line 73
>     except getopt.GetoptError as err:
>                                ^
> SyntaxError: invalid syntax
> 
> Any ideas?
> My Debian 4.0 has Python 2.4.4.

Hi Eric,
Yes, it's the same issue.  This patch will solve this particular problem
but you will hit others with Python 2.4.4.  You need Python 2.5 or
later.

Debian 4.0 (etch) is End of Lifed and no longer supported by the Debian
project.

Two options:

1. Install a modern distro (get security updates, modern tools, etc).

or

2. Build the latest Python 2.x release from source at
   http://python.org/.

Stefan
Stefan Hajnoczi April 27, 2012, 10:08 a.m. UTC | #7
On Fri, Apr 27, 2012 at 09:27:35AM +0200, Erik Rull wrote:
> On April 26, 2012 at 7:02 PM Erik Rull <erik.rull@rdsoftware.de> wrote:
> Finally I managed installing python 2.5 on my debian box - but it's not
> better:
> 
> python -V reports now python 2.5
> 
> The error message when pressing <tab> is still the same:

If the Python exception still reports the "except Foo as e:" syntax as
the error, then you have not applied this patch to your source tree.

Please post the error message you are getting.

It might be worth running ./configure --python=/path/to/python2.5 just
to ensure it picks up the right Python.

Stefan
Erik Rull April 27, 2012, 10:50 a.m. UTC | #8
On April 27, 2012 at 12:08 PM Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com> wrote:

> On Fri, Apr 27, 2012 at 09:27:35AM +0200, Erik Rull wrote:
> > On April 26, 2012 at 7:02 PM Erik Rull <erik.rull@rdsoftware.de> wrote:
> > Finally I managed installing python 2.5 on my debian box - but it's not
> > better:
> >
> > python -V reports now python 2.5
> >
> > The error message when pressing <tab> is still the same:
>
> If the Python exception still reports the "except Foo as e:" syntax as
> the error, then you have not applied this patch to your source tree.
>
> Please post the error message you are getting.
>
> It might be worth running ./configure --python=/path/to/python2.5 just
> to ensure it picks up the right Python.
>
> Stefan
>
>


Thanks for pointing this out another time :-) My mistake, seems to be fine
now!

Changing the operating system - sounds good, but currently due to other
dependencies not too easy.

Best regards,

Erik
Peter Maydell April 27, 2012, 11:02 a.m. UTC | #9
2012/4/27 Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>:
> Yes, it's the same issue.  This patch will solve this particular problem
> but you will hit others with Python 2.4.4.  You need Python 2.5 or
> later.

...perhaps we should update the configure python version check to
complain about python being too old as well as too new?

-- PMM
Stefan Hajnoczi April 27, 2012, 11:10 a.m. UTC | #10
On Fri, Apr 27, 2012 at 12:02 PM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> 2012/4/27 Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>:
>> Yes, it's the same issue.  This patch will solve this particular problem
>> but you will hit others with Python 2.4.4.  You need Python 2.5 or
>> later.
>
> ...perhaps we should update the configure python version check to
> complain about python being too old as well as too new?

Good idea.  I will send a patch.

Stefan
Erik Rull April 27, 2012, 11:14 a.m. UTC | #11
On April 27, 2012 at 1:02 PM Peter Maydell <peter.maydell@linaro.org>
wrote:

> 2012/4/27 Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>:
> > Yes, it's the same issue.  This patch will solve this particular
problem
> > but you will hit others with Python 2.4.4.  You need Python 2.5 or
> > later.
>
> ...perhaps we should update the configure python version check to
> complain about python being too old as well as too new?
>
> -- PMM

Hi Peter,

this will work only partly. When pressing tab in the configure command line
you already get an error caused by python. Additionally "make distclean" is
also no longer possible because this causes sometimes a call of configure
:-)

Best regards,

Erik
Stefan Hajnoczi April 27, 2012, 12:15 p.m. UTC | #12
On Wed, Apr 25, 2012 at 4:29 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Wed, Apr 25, 2012 at 2:35 PM, Andreas Färber <andreas.faerber@web.de> wrote:
>> Am 25.04.2012 11:42, schrieb Stefan Hajnoczi:
>>> The newer "except <exception-type> as <exception>:" syntax is not
>>> supported by Python 2.5, we need to use "except <exception-type>,
>>> <exception>:".
>>>
>>> Tested all trace backends with Python 2.5.6.
>>>
>>> Reported-by: Andreas Färber <afaerber@suse.de>
>>> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>>
>> Lightly
>>
>> Tested-by: Andreas Färber <andreas.faerber@web.de>
>>
>> Works with:
>> 2.5.1 (Mac OS X v10.5.8),
>> 2.6.1 (Mac OS X v10.6.8) and
>> 2.6.4 (OpenIndiana oi_151a).
>>
>> Thanks a lot!
>>
>> However, it still breaks with different errors on Python 2.3.3 and 2.4.6
>> (Solaris 10 U9).
>
> Solaris releases tend to be supported for a very long time.  I don't
> think we should restrict ourselves to glib, python, and other
> dependencies from the Solaris 10 era (actually Solaris 9 is still
> supported too!).
>
> We need to draw the line somewhere.  Python 2.5 was released on
> September 19, 2006.  It's available for Mac ppc and Solaris.

I just noticed that RHEL 5 ships Python 2.4, which means a lot of
RHEL/CentOS 5 hosts that are still out there will also break.

Let's bring back the requirement to Python 2.4.

Stefan
Stefan Hajnoczi April 27, 2012, 2:24 p.m. UTC | #13
On Wed, Apr 25, 2012 at 10:42 AM, Stefan Hajnoczi
<stefanha@linux.vnet.ibm.com> wrote:
> The newer "except <exception-type> as <exception>:" syntax is not
> supported by Python 2.5, we need to use "except <exception-type>,
> <exception>:".
>
> Tested all trace backends with Python 2.5.6.
>
> Reported-by: Andreas Färber <afaerber@suse.de>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  scripts/tracetool.py |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

I just sent out a new series which makes the appopriate Python 2.4
fixes and adds a check to ./configure.

This patch can be dropped.

Stefan
diff mbox

Patch

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