I have been testing the python3 changes committed to xen and found a few
issues. There are a couple of ocaml python build scripts that don't work
for me with python3, and I needed a few fixes to get pygrub to work,
mostly due to the change from strings to bytes. I am attaching the patch I
put together in testing to get these things to work to illustrate where
the problems are and in case it is useful to others, though I believe at
least some of it isn't compatible with python2.
Michael Young
--- xen-4.12.0-rc5/tools/ocaml/libs/xentoollog/genlevels.py.orig
2019-03-06 14:42:49.000000000 +0000
+++ xen-4.12.0-rc5/tools/ocaml/libs/xentoollog/genlevels.py 2019-03-13
21:33:59.805930989 +0000
@@ -1,6 +1,7 @@
#!/usr/bin/python
import sys
+from functools import reduce
def read_levels():
f = open('../../../libs/toollog/include/xentoollog.h', 'r')
@@ -86,14 +87,14 @@
def autogen_header(open_comment, close_comment):
s = open_comment + " AUTO-GENERATED FILE DO NOT EDIT " + close_comment +
"\n"
s += open_comment + " autogenerated by \n"
- s += reduce(lambda x,y: x + " ", range(len(open_comment + " ")), "")
+ s += reduce(lambda x,y: x + " ", list(range(len(open_comment + " "))), "")
s += "%s" % " ".join(sys.argv)
s += "\n " + close_comment + "\n\n"
return s
if __name__ == '__main__':
if len(sys.argv) < 3:
- print >>sys.stderr, "Usage: genlevels.py <mli> <ml> <c-inc>"
+ print("Usage: genlevels.py <mli> <ml> <c-inc>", file=sys.stderr)
sys.exit(1)
levels, olevels = read_levels()
--- xen-4.12.0-rc5/tools/ocaml/libs/xl/genwrap.py.orig 2019-03-06
14:42:49.000000000 +0000
+++ xen-4.12.0-rc5/tools/ocaml/libs/xl/genwrap.py 2019-03-13
21:34:00.674962832 +0000
@@ -3,6 +3,7 @@
import sys,os
import idl
+from functools import reduce
# typename -> ( ocaml_type, c_from_ocaml, ocaml_from_c )
builtins = {
@@ -78,7 +79,7 @@
elif isinstance(ty,idl.Array):
return "%s array" % ocaml_type_of(ty.elem_type)
elif isinstance(ty,idl.Builtin):
- if not builtins.has_key(ty.typename):
+ if ty.typename not in builtins:
raise NotImplementedError("Unknown Builtin %s (%s)" %
(ty.typename, type(ty)))
typename,_,_ = builtins[ty.typename]
if not typename:
@@ -251,7 +252,7 @@
else:
s += "\texternal default : ctx -> %sunit -> t =
\"stub_libxl_%s_init\"\n" % (union_args, ty.rawname)
- if functions.has_key(ty.rawname):
+ if ty.rawname in functions:
for name,args in functions[ty.rawname]:
s += "\texternal %s : " % name
s += " -> ".join(args)
@@ -278,7 +279,7 @@
else:
s += "%s = Int_val(%s);" % (c, o)
elif isinstance(ty,idl.Builtin):
- if not builtins.has_key(ty.typename):
+ if ty.typename not in builtins:
raise NotImplementedError("Unknown Builtin %s (%s)" %
(ty.typename, type(ty)))
_,fn,_ = builtins[ty.typename]
if not fn:
@@ -375,7 +376,7 @@
else:
s += "%s = Val_int(%s);" % (o, c)
elif isinstance(ty,idl.Builtin):
- if not builtins.has_key(ty.typename):
+ if ty.typename not in builtins:
raise NotImplementedError("Unknown Builtin %s (%s)" %
(ty.typename, type(ty)))
_,_,fn = builtins[ty.typename]
if not fn:
@@ -513,14 +514,14 @@
def autogen_header(open_comment, close_comment):
s = open_comment + " AUTO-GENERATED FILE DO NOT EDIT " + close_comment +
"\n"
s += open_comment + " autogenerated by \n"
- s += reduce(lambda x,y: x + " ", range(len(open_comment + " ")), "")
+ s += reduce(lambda x,y: x + " ", list(range(len(open_comment + " "))), "")
s += "%s" % " ".join(sys.argv)
s += "\n " + close_comment + "\n\n"
return s
if __name__ == '__main__':
if len(sys.argv) < 4:
- print >>sys.stderr, "Usage: genwrap.py <idl> <mli> <ml> <c-inc>"
+ print("Usage: genwrap.py <idl> <mli> <ml> <c-inc>", file=sys.stderr)
sys.exit(1)
(_,types) = idl.parse(sys.argv[1])
@@ -533,7 +534,7 @@
for t in blacklist:
if t not in [ty.rawname for ty in types]:
- print "unknown type %s in blacklist" % t
+ print("unknown type %s in blacklist" % t)
types = [ty for ty in types if not ty.rawname in blacklist]
@@ -564,7 +565,7 @@
cinc.write("\n")
cinc.write(gen_Val_ocaml(ty))
cinc.write("\n")
- if functions.has_key(ty.rawname):
+ if ty.rawname in functions:
cinc.write(gen_c_stub_prototype(ty, functions[ty.rawname]))
cinc.write("\n")
if ty.init_fn is not None:
--- xen-4.12.0-rc6/tools/pygrub/src/GrubConf.py.orig 2019-03-24
22:44:05.502581989 +0000
+++ xen-4.12.0-rc6/tools/pygrub/src/GrubConf.py 2019-03-24 22:49:14.025934786
+0000
@@ -230,10 +230,10 @@
def _get_default(self):
return self._default
def _set_default(self, val):
- if val == "saved":
+ if val == "saved" or not val.isdecimal():
self._default = 0
else:
- self._default = val
+ self._default = int(val)
if self._default < 0:
raise ValueError("default must be positive number")
--- xen-4.12.0-rc6/tools/pygrub/src/pygrub.orig 2019-03-24 22:44:05.503582025
+0000
+++ xen-4.12.0-rc6/tools/pygrub/src/pygrub 2019-03-24 22:48:24.446113809
+0000
@@ -457,7 +457,7 @@
# limit read size to avoid pathological cases
buf = f.read(FS_READ_MAX)
del f
- self.cf.parse(buf)
+ self.cf.parse(buf.decode())
def image_index(self):
if isinstance(self.cf.default, int):
@@ -960,5 +960,5 @@
ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args,
"\0")
sys.stdout.flush()
- os.write(fd, ostring)
+ os.write(fd, ostring.encode())
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel