]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
tools/xen-foreign: Update python scripts to be Py3 compatible for-4.13
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 4 Mar 2019 18:31:48 +0000 (18:31 +0000)
committerWei Liu <wei.liu2@citrix.com>
Wed, 6 Mar 2019 13:12:41 +0000 (13:12 +0000)
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@eu.citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/include/xen-foreign/mkchecker.py
tools/include/xen-foreign/mkheader.py

index fdad869a912c72f77eb380008950128708fc7bc8..199b0eebbc50ab71e682b335158e0d1065d52fb8 100644 (file)
@@ -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:
index 97e0c7a9843e1307992608c1c1eae7a2bb369152..d876831900e339f3e52f34856a64c6b641c63052 100644 (file)
@@ -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