From 29665dcba154cd10508616e47f92ebcb335513ea Mon Sep 17 00:00:00 2001 From: Tom Williams Date: Fri, 4 Jan 2019 18:39:04 +0000 Subject: [PATCH] uHAL : Update tools to support Python 3; refs #127 --- uhal/tools/scripts/gen_ipbus_addr_decode | 13 ++++++++++--- uhal/tools/scripts/uhal_inspect_registers.py | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/uhal/tools/scripts/gen_ipbus_addr_decode b/uhal/tools/scripts/gen_ipbus_addr_decode index ed2054881..18accdab1 100755 --- a/uhal/tools/scripts/gen_ipbus_addr_decode +++ b/uhal/tools/scripts/gen_ipbus_addr_decode @@ -18,6 +18,9 @@ options: (default /opt/cactus/etc/uhal/tools/ipbus_addr_decode.vhd) """ + +from __future__ import print_function + import getopt import sys import os.path @@ -27,6 +30,10 @@ import math import uhal #=========================================================================================== +# In Python 3 "xrange" doesn't exist, since Python 3's "range" is just as efficient as Python 2's "xrange" +if (sys.version_info[0] > 2): + xrange = range + class BitArray: @@ -189,7 +196,7 @@ def main(): template_fn = "/opt/cactus/etc/uhal/tools/ipbus_addr_decode.vhd" try: opts, args = getopt.getopt(sys.argv[1:], "vdnht:", ["verbose","debug","dry-run","help","template="]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: log.critical(__doc__) sys.exit(EXIT_CODE_ARG_PARSING_ERROR) for o, a in opts: @@ -200,7 +207,7 @@ def main(): log.setLevel(logging.DEBUG) uhal.setLogLevelTo(uhal.LogLevel.DEBUG) elif o in ("-h", "--help"): - print __doc__ + print(__doc__) sys.exit(0) elif o in ("-t", "--template"): template_fn = a @@ -300,7 +307,7 @@ def main(): .replace("INSERT_SEL_WIDTH_HERE","%s"%ipbus_sel_width)\ .replace("PACKAGENAME",moduleName)) vhdlfile.close() - print "VHDL decode file saved: ", vhdlfilename + print("VHDL decode file saved: ", vhdlfilename) if __name__ == '__main__': main() diff --git a/uhal/tools/scripts/uhal_inspect_registers.py b/uhal/tools/scripts/uhal_inspect_registers.py index 9697c3c4f..15cd612ef 100755 --- a/uhal/tools/scripts/uhal_inspect_registers.py +++ b/uhal/tools/scripts/uhal_inspect_registers.py @@ -4,6 +4,8 @@ This script prints the values in a remote device, of registers below a specified uHAL node. """ +from __future__ import print_function + import argparse import uhal @@ -43,8 +45,8 @@ def snapshot(node, regex): cm = uhal.ConnectionManager(args.conn_file) device = cm.getDevice(args.device_id) - print 'Values of registers below node "'+args.reg_name+'" in device "'+args.device_id+'"' + print('Values of registers below node "'+args.reg_name+'" in device "'+args.device_id+'"') for name, value in snapshot(device.getNode(args.reg_name), args.regex): - print " +", name, ":", hex(value) + print(" +", name, ":", hex(value))