[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC-for-4.12] tools/xen-foreign: Update python scripts to be Py3 compatible



The issues are:
 * dict.has_key() was completely removed in Py3
 * dict.keys() is an iterable rather than list in Py3, so .sort() doesn't work.
 * list.sort(cmp=) was deprecated in Py2.4 and removed in Py3.  Replace it
   with a key= sort instead.

This is all compatible with Py2.4 and later, which is when the sorted()
builtin was introduced.  Tested with Py2.7 and Py3.4

Reported-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
CC: Ian Jackson <ian.jackson@xxxxxxxxxx>
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
CC: Tim Deegan <tim@xxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>
CC: Julien Grall <julien.grall@xxxxxxx>
CC: Juergen Gross <jgross@xxxxxxxx>

This is a nice-to-have for 4.12 because it makes our build system more
compatible with bleeding edge distros.

I've not got the time to figure out why mkheader needs to process types in
reverse order of their type names, but checker.c doesn't compile if the list
is sorted differently.
---
 tools/include/xen-foreign/mkchecker.py | 2 +-
 tools/include/xen-foreign/mkheader.py  | 4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/include/xen-foreign/mkchecker.py 
b/tools/include/xen-foreign/mkchecker.py
index fdad869..199b0ee 100644
--- a/tools/include/xen-foreign/mkchecker.py
+++ b/tools/include/xen-foreign/mkchecker.py
@@ -37,7 +37,7 @@ for struct in structs:
     f.write('\tprintf("%%-25s |", "%s");\n' % struct);
     for a in archs:
         s = struct + "_" + a;
-        if compat_arches.has_key(a):
+        if a in compat_arches:
             compat = compat_arches[a]
             c = struct + "_" + compat;
         else:
diff --git a/tools/include/xen-foreign/mkheader.py 
b/tools/include/xen-foreign/mkheader.py
index 97e0c7a..d876831 100644
--- a/tools/include/xen-foreign/mkheader.py
+++ b/tools/include/xen-foreign/mkheader.py
@@ -205,9 +205,7 @@ for struct in structs:
     output = re.sub("\\b(%s)_t\\b" % struct, "\\1_%s_t" % arch, output);
 
 # replace: integer types
-integers = inttypes[arch].keys();
-integers.sort(lambda a, b: cmp(len(b),len(a)));
-for type in integers:
+for type in sorted(inttypes[arch].keys(), key = lambda x: -len(x)):
     output = re.sub("\\b%s\\b" % type, inttypes[arch][type], output);
 
 # print results
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.