From patchwork Mon Apr 1 10:32:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 10879671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED0101708 for ; Mon, 1 Apr 2019 10:34:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D75EA2808F for ; Mon, 1 Apr 2019 10:34:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBAD0286A9; Mon, 1 Apr 2019 10:34:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AAB8287B7 for ; Mon, 1 Apr 2019 10:34:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hAuFO-0008M5-Fs; Mon, 01 Apr 2019 10:32:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hAuFN-0008Ky-66 for xen-devel@lists.xenproject.org; Mon, 01 Apr 2019 10:32:57 +0000 X-Inumbo-ID: 81fdcc06-5469-11e9-8ffe-73677c4328d0 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 81fdcc06-5469-11e9-8ffe-73677c4328d0; Mon, 01 Apr 2019 10:32:54 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,296,1549929600"; d="scan'208";a="82363728" From: Wei Liu To: Date: Mon, 1 Apr 2019 11:32:38 +0100 Message-ID: <20190401103238.15649-5-wei.liu2@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190401103238.15649-1-wei.liu2@citrix.com> References: <20190401103238.15649-1-wei.liu2@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 4/4] tools/ocaml: make python scripts 2 and 3 compatible X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , David Scott , Wei Liu , Christian Lindig , m.a.young@durham.ac.uk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Wei Liu Reviewed-by: Andrew Cooper Acked-by: Christian Lindig --- 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 " + print("Usage: genlevels.py ", 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 " + print("Usage: genwrap.py ", 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: