Message ID | 20190401103238.15649-1-wei.liu2@citrix.com (mailing list archive) |
---|---|
Headers | show |
Series | More python fixes | expand |
On Mon, 1 Apr 2019, Wei Liu wrote: > Wei Liu (4): > pygrub: fix message in grub parser > pygrub/grub: always use integer for default entry > pygrub: decode string in Python 3 > tools/ocaml: make python scripts 2 and 3 compatible > > tools/ocaml/libs/xentoollog/genlevels.py | 5 ++++- > tools/ocaml/libs/xl/genwrap.py | 17 ++++++++++------- > tools/pygrub/src/GrubConf.py | 8 ++++++-- > tools/pygrub/src/pygrub | 5 ++++- > 4 files changed, 24 insertions(+), 11 deletions(-) There is a bit missing compared to my original patch which is to convert the string back to bytes for the final write out and avoid the error Traceback (most recent call last): File "/tmp/xencode/usr/libexec/xen/bin/pygrub", line 967, in <module> os.write(fd, ostring) TypeError: a bytes-like object is required, not 'str' The attached patch works for me in a quick test on python3 though I haven't tested it on python2 yet. Michael Young --- xen-4.12.0/tools/pygrub/src/pygrub.orig 2019-04-01 21:25:33.206405995 +0100 +++ xen-4.12.0/tools/pygrub/src/pygrub 2019-04-01 21:27:36.179929105 +0100 @@ -963,5 +963,8 @@ ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\0") sys.stdout.flush() - os.write(fd, ostring) + if sys.version_info[0] < 3: + os.write(fd, ostring) + else: + os.write(fd, ostring.encode())
On Mon, Apr 01, 2019 at 08:36:44PM +0000, YOUNG, MICHAEL A. wrote: > On Mon, 1 Apr 2019, Wei Liu wrote: > > > Wei Liu (4): > > pygrub: fix message in grub parser > > pygrub/grub: always use integer for default entry > > pygrub: decode string in Python 3 > > tools/ocaml: make python scripts 2 and 3 compatible > > > > tools/ocaml/libs/xentoollog/genlevels.py | 5 ++++- > > tools/ocaml/libs/xl/genwrap.py | 17 ++++++++++------- > > tools/pygrub/src/GrubConf.py | 8 ++++++-- > > tools/pygrub/src/pygrub | 5 ++++- > > 4 files changed, 24 insertions(+), 11 deletions(-) > > There is a bit missing compared to my original patch which is to convert > the string back to bytes for the final write out and avoid the error > > Traceback (most recent call last): > File "/tmp/xencode/usr/libexec/xen/bin/pygrub", line 967, in <module> > os.write(fd, ostring) > TypeError: a bytes-like object is required, not 'str' > > The attached patch works for me in a quick test on python3 though I > haven't tested it on python2 yet. > > Michael Young > --- xen-4.12.0/tools/pygrub/src/pygrub.orig 2019-04-01 21:25:33.206405995 +0100 > +++ xen-4.12.0/tools/pygrub/src/pygrub 2019-04-01 21:27:36.179929105 +0100 > @@ -963,5 +963,8 @@ > ostring = format_simple(bootcfg["kernel"], bootcfg["ramdisk"], args, "\0") > > sys.stdout.flush() > - os.write(fd, ostring) > + if sys.version_info[0] < 3: > + os.write(fd, ostring) > + else: > + os.write(fd, ostring.encode()) > This should work. I will fold this in to the pygrub patch. Thanks for spotting my mistake. Wei.