From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
David Scott <dave@recoil.org>, Wei Liu <wei.liu2@citrix.com>,
Christian Lindig <christian.lindig@citrix.com>,
m.a.young@durham.ac.uk
Subject: [PATCH 4/4] tools/ocaml: make python scripts 2 and 3 compatible
Date: Mon, 1 Apr 2019 11:32:38 +0100 [thread overview]
Message-ID: <20190401103238.15649-5-wei.liu2@citrix.com> (raw)
In-Reply-To: <20190401103238.15649-1-wei.liu2@citrix.com>
1. Explicitly import reduce because that's required in 3.
2. Change print to function.
3. Eliminate invocations of has_key.
Signed-off-by: M A Young <m.a.young@durham.ac.uk>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/ocaml/libs/xentoollog/genlevels.py | 5 ++++-
tools/ocaml/libs/xl/genwrap.py | 17 ++++++++++-------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/tools/ocaml/libs/xentoollog/genlevels.py b/tools/ocaml/libs/xentoollog/genlevels.py
index 8c233c59b1..f9cf853e26 100755
--- a/tools/ocaml/libs/xentoollog/genlevels.py
+++ b/tools/ocaml/libs/xentoollog/genlevels.py
@@ -1,6 +1,9 @@
#!/usr/bin/python
+from __future__ import print_function
+
import sys
+from functools import reduce
def read_levels():
f = open('../../../libs/toollog/include/xentoollog.h', 'r')
@@ -93,7 +96,7 @@ def autogen_header(open_comment, close_comment):
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()
diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py
index 815c1cb0e3..7bf26bdcd8 100644
--- a/tools/ocaml/libs/xl/genwrap.py
+++ b/tools/ocaml/libs/xl/genwrap.py
@@ -1,6 +1,9 @@
#!/usr/bin/python
+from __future__ import print_function
+
import sys,os
+from functools import reduce
import idl
@@ -78,7 +81,7 @@ def ocaml_type_of(ty):
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 +254,7 @@ def gen_ocaml_ml(ty, interface, indent=""):
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 +281,7 @@ def c_val(ty, c, o, indent="", parent = None):
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 +378,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
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:
@@ -520,7 +523,7 @@ def autogen_header(open_comment, close_comment):
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 +536,7 @@ if __name__ == '__main__':
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 +567,7 @@ if __name__ == '__main__':
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:
--
2.20.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-04-01 10:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-01 10:32 [PATCH 0/4] More python fixes Wei Liu
2019-04-01 10:32 ` [PATCH 1/4] pygrub: fix message in grub parser Wei Liu
2019-04-01 16:16 ` Andrew Cooper
2019-04-01 10:32 ` [PATCH 2/4] pygrub/grub: always use integer for default entry Wei Liu
2019-04-01 16:20 ` Andrew Cooper
2019-04-01 10:32 ` [PATCH 3/4] pygrub: decode string in Python 3 Wei Liu
2019-04-01 16:21 ` Andrew Cooper
2019-04-01 10:32 ` Wei Liu [this message]
2019-04-01 16:22 ` [PATCH 4/4] tools/ocaml: make python scripts 2 and 3 compatible Andrew Cooper
2019-04-01 16:24 ` Christian Lindig
2019-04-01 20:36 ` [PATCH 0/4] More python fixes YOUNG, MICHAEL A.
2019-04-02 8:18 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190401103238.15649-5-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=christian.lindig@citrix.com \
--cc=dave@recoil.org \
--cc=ian.jackson@eu.citrix.com \
--cc=m.a.young@durham.ac.uk \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).