[PATCH v2 libevdev] Change event name generate script to be python 2/3 compatible

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 28 18:45:11 PDT 2013


On Wed, Aug 28, 2013 at 10:27:47AM +0200, Benjamin Tissoires wrote:
> 
> 
> On 26/08/13 01:15, Peter Hutterer wrote:
> > Python 3 doesn't have a print statement, only a print function. Replace
> > all calls in the form
> >    print "blah"
> > with
> >    print("blah")
> > 
> > regex:
> >   s/print "(.*)/print("\1/
> 
> You should use instead the program 2to3 (from package python-tools),
> which will do the job for you and add an extra:
> 
> diff --git a/libevdev/make-event-names.py b/libevdev/make-event-names.py
> index d946dc2..018a228 100755
> --- a/libevdev/make-event-names.py
> +++ b/libevdev/make-event-names.py
> @@ -46,7 +46,7 @@ def print_bits(bits, prefix):
>  		return
>  	print("static const char * const %s_map[%s_MAX + 1] = {" % (prefix, prefix.upper()))
>  	print("	[0 ... %s_MAX] = NULL," % prefix.upper())
> -	for val, name in getattr(bits, prefix).items():
> +	for val, name in list(getattr(bits, prefix).items()):
>  		print("	[%s] = \"%s\"," % (name, name))
>  	print("};")
>  	print("")
> @@ -56,7 +56,7 @@ def print_python_bits(bits, prefix):
>  		return
>  
>  	print("%s_map = {" % (prefix))
> -	for val, name in getattr(bits, prefix).items():
> +	for val, name in list(getattr(bits, prefix).items()):
>  		print("	%d : \"%s\"," % (val, name))
>  	print("}")
>  	print("for k, v in %s_map.items():" % (prefix))
> @@ -87,7 +87,7 @@ def print_map(bits):
>  def print_python_map(bits):
>  	print("map = {")
>  
> -	for val, name in getattr(bits, "ev").items():
> +	for val, name in list(getattr(bits, "ev").items()):
>  		name = name[3:]
>  		if name == "REP" or name == "PWR"  or name == "FF_STATUS"  or name == "MAX":
>  			continue
> --
> 
> > 
> > Print as function requires Python 2.6 which is reasonable enough given
> > that even RHEL6 ships that.
> 
> I remember receiving 2 years ago complains about the str.format() use, but
> I don't think we should really care as those old distro will not ship
> libevdev :)
> 
> > 
> > Even though it's not needed for 2.6, use
> > 	from __future__ import print_function
> > to avoid accidentally introducing a print statement in the future.
> > With this line, print "blah" is now a syntax error in python 2.
> 
> Yep :) But 2to3 does not add this statement, so it has to be added by hand :(
> 
> > 
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> 
> I'd be happy if you squash the above diff and change the commit message to
> say that the patch is produced through 2to3 (so this would show that the
> patch is rather automated). Anyway:
> 
> Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

done, thanks.

Cheers,
   Peter


More information about the Input-tools mailing list