diff options
Diffstat (limited to 'host')
-rw-r--r--[-rwxr-xr-x] | host/utils/usrp2_card_burner.py | 38 | ||||
-rw-r--r--[-rwxr-xr-x] | host/utils/usrp2_card_burner_gui.py | 87 | ||||
-rw-r--r--[-rwxr-xr-x] | host/utils/usrp2_recovery.py | 12 | ||||
-rw-r--r--[-rwxr-xr-x] | host/utils/usrp_n2xx_net_burner.py | 68 | ||||
-rw-r--r--[-rwxr-xr-x] | host/utils/usrp_n2xx_net_burner_gui.py | 75 |
5 files changed, 149 insertions, 131 deletions
diff --git a/host/utils/usrp2_card_burner.py b/host/utils/usrp2_card_burner.py index 1db5e59ce..cb3cc53f6 100755..100644 --- a/host/utils/usrp2_card_burner.py +++ b/host/utils/usrp2_card_burner.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,7 +19,11 @@ import platform import tempfile import subprocess -import urllib +try: + import urllib.request +except ImportError: + import urllib + urllib.request = urllib import optparse import math import os @@ -47,15 +51,15 @@ def command(*args): ) ret = p.wait() verbose = p.stdout.read() - if ret != 0: raise Exception, verbose + if ret != 0: raise Exception(verbose) return verbose def get_dd_path(): if platform.system() == 'Windows': dd_path = os.path.join(tempfile.gettempdir(), 'dd.exe') if not os.path.exists(dd_path): - print 'Downloading dd.exe to %s'%dd_path - dd_bin = urllib.urlopen('http://www.ettus.com/downloads/dd.exe').read() + print('Downloading dd.exe to %s'%dd_path) + dd_bin = urllib.request.urlopen('http://www.ettus.com/downloads/dd.exe').read() open(dd_path, 'wb').write(dd_bin) return dd_path return 'dd' @@ -80,7 +84,7 @@ def get_raw_device_hints(): return info.split(key)[-1].split()[0] def get_info_list(output): in_info = False - for line in output.splitlines(): + for line in str(output).splitlines(): if line.startswith('\\\\'): in_info = True; info = '' elif in_info and not line.strip(): in_info = False; yield info if in_info: info += '\n'+line.strip() @@ -97,7 +101,7 @@ def get_raw_device_hints(): if key in info: return extract_info_value(info, key) return info.splitlines()[0].strip() - return sorted(set(map(extract_info_name, filter(is_info_valid, get_info_list(command(get_dd_path(), '--list')))))) + return sorted(set(map(extract_info_name, list(filter(is_info_valid, get_info_list(command(get_dd_path(), '--list'))))))) #################################################################### # Platform Linux: parse procfs /proc/partitions @@ -120,15 +124,15 @@ def get_raw_device_hints(): # Platform Mac OS X: parse diskutil list and info commands #################################################################### if platform.system() == 'Darwin': - devs = map(lambda d: d.split()[0], filter(lambda l: l.startswith('/dev'), command('diskutil', 'list').splitlines())) + devs = [d.split()[0] for d in [l for l in command('diskutil', 'list').splitlines() if l.startswith('/dev')]] def output_to_info(output): - return dict([map(str.strip, pair.lower().split(':')) for pair in filter(lambda l: ':' in l, output.splitlines())]) + return dict([list(map(str.strip, pair.lower().split(':'))) for pair in [l for l in output.splitlines() if ':' in l]]) def is_dev_valid(dev): info = output_to_info(command('diskutil', 'info', dev)) try: - if info.has_key('internal'): assert info['internal'] == 'no' - if info.has_key('ejectable'): assert info['ejectable'] == 'yes' - if info.has_key('total size'): + if 'internal' in info: assert info['internal'] == 'no' + if 'ejectable' in info: assert info['ejectable'] == 'yes' + if 'total size' in info: size_match = re.match('^.*\((\d+)\s*bytes\).*$', info['total size']) if size_match: assert int(size_match.groups()[0]) <= MAX_SD_CARD_SIZE return True @@ -196,7 +200,7 @@ def write_image(image_file, device_file, offset): def write_and_verify(image_file, device_file, offset): if os.path.getsize(image_file) > MAX_FILE_SIZE: - raise Exception, 'Image file larger than %d bytes!'%MAX_FILE_SIZE + raise Exception('Image file larger than %d bytes!'%MAX_FILE_SIZE) return '%s\n%s'%( write_image( image_file=image_file, @@ -231,8 +235,8 @@ def get_options(): (options, args) = parser.parse_args() if options.list: - print 'Possible raw devices:' - print ' ' + '\n '.join(get_raw_device_hints()) + print('Possible raw devices:') + print(' ' + '\n '.join(get_raw_device_hints())) exit() return options @@ -242,5 +246,5 @@ def get_options(): ######################################################################## if __name__=='__main__': options = get_options() - if not options.dev: raise Exception, 'no raw device path specified' - print burn_sd_card(dev=options.dev, fw=options.fw, fpga=options.fpga) + if not options.dev: raise Exception('no raw device path specified') + print(burn_sd_card(dev=options.dev, fw=options.fw, fpga=options.fpga)) diff --git a/host/utils/usrp2_card_burner_gui.py b/host/utils/usrp2_card_burner_gui.py index 58b7a514a..2941629b9 100755..100644 --- a/host/utils/usrp2_card_burner_gui.py +++ b/host/utils/usrp2_card_burner_gui.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,10 +17,17 @@ # import usrp2_card_burner #import implementation -import Tkinter, tkFileDialog, tkFont, tkMessageBox +try: + import tkinter, tkinter.filedialog, tkinter.font, tkinter.messagebox +except ImportError: + import tkFileDialog, tkFont, tkMessageBox + import Tkinter as tkinter + tkinter.filedialog = tkFileDialog + tkinter.font = tkFont + tkinter.messagebox = tkMessageBox import os -class BinFileEntry(Tkinter.Frame): +class BinFileEntry(tkinter.Frame): """ Simple file entry widget for getting the file path of bin files. Combines a label, entry, and button with file dialog callback. @@ -28,15 +35,15 @@ class BinFileEntry(Tkinter.Frame): def __init__(self, root, what, def_path=''): self._what = what - Tkinter.Frame.__init__(self, root) - Tkinter.Label(self, text=what+":").pack(side=Tkinter.LEFT) - self._entry = Tkinter.Entry(self, width=50) - self._entry.insert(Tkinter.END, def_path) - self._entry.pack(side=Tkinter.LEFT) - Tkinter.Button(self, text="...", command=self._button_cb).pack(side=Tkinter.LEFT) + tkinter.Frame.__init__(self, root) + tkinter.Label(self, text=what+":").pack(side=tkinter.LEFT) + self._entry = tkinter.Entry(self, width=50) + self._entry.insert(tkinter.END, def_path) + self._entry.pack(side=tkinter.LEFT) + tkinter.Button(self, text="...", command=self._button_cb).pack(side=tkinter.LEFT) def _button_cb(self): - filename = tkFileDialog.askopenfilename( + filename = tkinter.filedialog.askopenfilename( parent=self, filetypes=[('bin files', '*.bin'), ('all files', '*.*')], title="Select bin file for %s"%self._what, @@ -45,65 +52,65 @@ class BinFileEntry(Tkinter.Frame): # open file on your own if filename: - self._entry.delete(0, Tkinter.END) + self._entry.delete(0, tkinter.END) self._entry.insert(0, filename) def get_filename(self): return self._entry.get() -class DeviceEntryWidget(Tkinter.Frame): +class DeviceEntryWidget(tkinter.Frame): """ Simple entry widget for getting the raw device name. Combines a label, entry, and helpful text box with hints. """ def __init__(self, root, text=''): - Tkinter.Frame.__init__(self, root) + tkinter.Frame.__init__(self, root) - Tkinter.Button(self, text="Rescan for Devices", command=self._reload_cb).pack() + tkinter.Button(self, text="Rescan for Devices", command=self._reload_cb).pack() - self._hints = Tkinter.Listbox(self) + self._hints = tkinter.Listbox(self) self._hints.bind("<<ListboxSelect>>", self._listbox_cb) self._reload_cb() - self._hints.pack(expand=Tkinter.YES, fill=Tkinter.X) + self._hints.pack(expand=tkinter.YES, fill=tkinter.X) - frame = Tkinter.Frame(self) + frame = tkinter.Frame(self) frame.pack() - Tkinter.Label(frame, text="Raw Device:").pack(side=Tkinter.LEFT) - self._entry = Tkinter.Entry(frame, width=50) - self._entry.insert(Tkinter.END, text) - self._entry.pack(side=Tkinter.LEFT) + tkinter.Label(frame, text="Raw Device:").pack(side=tkinter.LEFT) + self._entry = tkinter.Entry(frame, width=50) + self._entry.insert(tkinter.END, text) + self._entry.pack(side=tkinter.LEFT) def _reload_cb(self): - self._hints.delete(0, Tkinter.END) + self._hints.delete(0, tkinter.END) for hint in usrp2_card_burner.get_raw_device_hints(): - self._hints.insert(Tkinter.END, hint) + self._hints.insert(tkinter.END, hint) def _listbox_cb(self, event): try: sel = self._hints.get(self._hints.curselection()[0]) - self._entry.delete(0, Tkinter.END) + self._entry.delete(0, tkinter.END) self._entry.insert(0, sel) - except Exception, e: print e + except Exception as e: print(e) def get_devname(self): return self._entry.get() -class SectionLabel(Tkinter.Label): +class SectionLabel(tkinter.Label): """ Make a text label with bold font. """ def __init__(self, root, text): - Tkinter.Label.__init__(self, root, text=text) + tkinter.Label.__init__(self, root, text=text) #set the font bold - f = tkFont.Font(font=self['font']) + f = tkinter.font.Font(font=self['font']) f['weight'] = 'bold' self['font'] = f.name -class USRP2CardBurnerApp(Tkinter.Frame): +class USRP2CardBurnerApp(tkinter.Frame): """ The top level gui application for the usrp2 sd card burner. Creates entry widgets and button with callback to write images. @@ -111,7 +118,7 @@ class USRP2CardBurnerApp(Tkinter.Frame): def __init__(self, root, dev, fw, fpga): - Tkinter.Frame.__init__(self, root) + tkinter.Frame.__init__(self, root) #pack the file entry widgets SectionLabel(self, text="Select Images").pack(pady=5) @@ -127,8 +134,8 @@ class USRP2CardBurnerApp(Tkinter.Frame): #the do it button SectionLabel(self, text="").pack(pady=5) - Tkinter.Label(self, text="Warning! This tool can overwrite your hard drive. Use with caution.").pack() - Tkinter.Button(self, text="Burn SD Card", command=self._burn).pack() + tkinter.Label(self, text="Warning! This tool can overwrite your hard drive. Use with caution.").pack() + tkinter.Button(self, text="Burn SD Card", command=self._burn).pack() def _burn(self): #grab strings from the gui @@ -138,31 +145,31 @@ class USRP2CardBurnerApp(Tkinter.Frame): #check input if not dev: - tkMessageBox.showerror('Error:', 'No device specified!') + tkinter.messagebox.showerror('Error:', 'No device specified!') return if not fw and not fpga: - tkMessageBox.showerror('Error:', 'No images specified!') + tkinter.messagebox.showerror('Error:', 'No images specified!') return if fw and not os.path.exists(fw): - tkMessageBox.showerror('Error:', 'Firmware image not found!') + tkinter.messagebox.showerror('Error:', 'Firmware image not found!') return if fpga and not os.path.exists(fpga): - tkMessageBox.showerror('Error:', 'FPGA image not found!') + tkinter.messagebox.showerror('Error:', 'FPGA image not found!') return #burn the sd card try: verbose = usrp2_card_burner.burn_sd_card(dev=dev, fw=fw, fpga=fpga) - tkMessageBox.showinfo('Verbose:', verbose) - except Exception, e: - tkMessageBox.showerror('Verbose:', 'Error: %s'%str(e)) + tkinter.messagebox.showinfo('Verbose:', verbose) + except Exception as e: + tkinter.messagebox.showerror('Verbose:', 'Error: %s'%str(e)) ######################################################################## # main ######################################################################## if __name__=='__main__': options = usrp2_card_burner.get_options() - root = Tkinter.Tk() + root = tkinter.Tk() root.title('USRP2 SD Card Burner') USRP2CardBurnerApp(root, dev=options.dev, fw=options.fw, fpga=options.fpga).pack() root.mainloop() diff --git a/host/utils/usrp2_recovery.py b/host/utils/usrp2_recovery.py index 5654e93d3..c7578d3a0 100755..100644 --- a/host/utils/usrp2_recovery.py +++ b/host/utils/usrp2_recovery.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ RECOVERY_ETHERTYPE = 0xbeee IP_RECOVERY_CODE = 'addr' def mac_addr_repr_to_binary_string(mac_addr): - return ''.join(map(lambda x: chr(int(x, 16)), mac_addr.split(':'))) + return ''.join([chr(int(x, 16)) for x in mac_addr.split(':')]) if __name__ == '__main__': parser = optparse.OptionParser(usage='usage: %prog [options]\n'+__doc__) @@ -48,12 +48,12 @@ if __name__ == '__main__': (options, args) = parser.parse_args() #create the raw socket - print "Opening raw socket on interface:", options.ifc + print("Opening raw socket on interface:", options.ifc) soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW) soc.bind((options.ifc, RECOVERY_ETHERTYPE)) #create the recovery packet - print "Loading packet with ip address:", options.new_ip + print("Loading packet with ip address:", options.new_ip) packet = struct.pack( '!6s6sH4s4s', mac_addr_repr_to_binary_string(BCAST_MAC_ADDR), @@ -63,6 +63,6 @@ if __name__ == '__main__': socket.inet_aton(options.new_ip), ) - print "Sending packet (%d bytes)"%len(packet) + print("Sending packet (%d bytes)"%len(packet)) soc.send(packet) - print "Done" + print("Done") diff --git a/host/utils/usrp_n2xx_net_burner.py b/host/utils/usrp_n2xx_net_burner.py index c715f3364..58d18fd2d 100755..100644 --- a/host/utils/usrp_n2xx_net_burner.py +++ b/host/utils/usrp_n2xx_net_burner.py @@ -137,12 +137,12 @@ class burner_socket(object): def init_update(self): out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_OHAI_LOL, seq(), 0, 0, "") try: in_pkt = self.send_and_recv(out_pkt) - except socket.timeout: raise Exception, "No response from device" + except socket.timeout: raise Exception("No response from device") (proto_ver, pktid, rxseq, ip_addr) = unpack_flash_ip_fmt(in_pkt) if pktid == update_id_t.USRP2_FW_UPDATE_ID_OHAI_OMG: - print "USRP-N2XX found." + print("USRP-N2XX found.") else: - raise Exception, "Invalid reply received from device." + raise Exception("Invalid reply received from device.") # print "Incoming:\n\tVer: %i\n\tID: %c\n\tSeq: %i\n\tIP: %i\n" % (proto_ver, chr(pktid), rxseq, ip_addr) @@ -153,14 +153,14 @@ class burner_socket(object): (proto_ver, pktid, rxseq, sector_size_bytes, memory_size_bytes) = unpack_flash_info_fmt(in_pkt) if pktid != update_id_t.USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) return (memory_size_bytes, sector_size_bytes) def burn_fw(self, fw, fpga, reset, safe): (flash_size, sector_size) = self.get_flash_info() - print "Flash size: %i\nSector size: %i\n\n" % (flash_size, sector_size) + print("Flash size: %i\nSector size: %i\n\n" % (flash_size, sector_size)) if fpga: if safe: image_location = SAFE_FPGA_IMAGE_LOCATION_ADDR @@ -170,20 +170,20 @@ class burner_socket(object): fpga_image = fpga_file.read() if len(fpga_image) > FPGA_IMAGE_SIZE_BYTES: - print "Error: FPGA image file too large." + print("Error: FPGA image file too large.") return 0 if not is_valid_fpga_image(fpga_image): - print "Error: Invalid FPGA image file." + print("Error: Invalid FPGA image file.") return 0 - print "Begin FPGA write: this should take about 1 minute..." + print("Begin FPGA write: this should take about 1 minute...") start_time = time.time() self.erase_image(image_location, FPGA_IMAGE_SIZE_BYTES) self.write_image(fpga_image, image_location) self.verify_image(fpga_image, image_location) - print "Time elapsed: %f seconds"%(time.time() - start_time) - print "\n\n" + print("Time elapsed: %f seconds"%(time.time() - start_time)) + print("\n\n") if fw: if safe: image_location = SAFE_FW_IMAGE_LOCATION_ADDR @@ -193,25 +193,25 @@ class burner_socket(object): fw_image = fw_file.read() if len(fw_image) > FW_IMAGE_SIZE_BYTES: - print "Error: Firmware image file too large." + print("Error: Firmware image file too large.") return 0 if not is_valid_fw_image(fw_image): - print "Error: Invalid firmware image file." + print("Error: Invalid firmware image file.") return 0 - print "Begin firmware write: this should take about 1 second..." + print("Begin firmware write: this should take about 1 second...") start_time = time.time() self.erase_image(image_location, FW_IMAGE_SIZE_BYTES) self.write_image(fw_image, image_location) self.verify_image(fw_image, image_location) - print "Time elapsed: %f seconds"%(time.time() - start_time) - print "\n\n" + print("Time elapsed: %f seconds"%(time.time() - start_time)) + print("\n\n") if reset: self.reset_usrp() def write_image(self, image, addr): - print "Writing image" + print("Writing image") self._status_cb("Writing") writedata = image #we split the image into smaller (256B) bits and send them down the wire @@ -222,14 +222,14 @@ class burner_socket(object): (proto_ver, pktid, rxseq, flash_addr, rxlength, data) = unpack_flash_args_fmt(in_pkt) if pktid != update_id_t.USRP2_FW_UPDATE_ID_WROTE_TEH_FLASHES_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) writedata = writedata[FLASH_DATA_PACKET_SIZE:] addr += FLASH_DATA_PACKET_SIZE self._progress_cb(float(len(image)-len(writedata))/len(image)) def verify_image(self, image, addr): - print "Verifying data" + print("Verifying data") self._status_cb("Verifying") readsize = len(image) readdata = str() @@ -242,26 +242,26 @@ class burner_socket(object): (proto_ver, pktid, rxseq, flash_addr, rxlength, data) = unpack_flash_args_fmt(in_pkt) if pktid != update_id_t.USRP2_FW_UPDATE_ID_KK_READ_TEH_FLASHES_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) readdata += data[:thisreadsize] readsize -= FLASH_DATA_PACKET_SIZE addr += FLASH_DATA_PACKET_SIZE self._progress_cb(float(len(readdata))/len(image)) - print "Read back %i bytes" % len(readdata) + print("Read back %i bytes" % len(readdata)) # print readdata # for i in range(256, 512): # print "out: %i in: %i" % (ord(image[i]), ord(readdata[i])) if readdata != image: - raise Exception, "Verify failed. Image did not write correctly." + raise Exception("Verify failed. Image did not write correctly.") else: - print "Success." + print("Success.") def read_image(self, image, size, addr): - print "Reading image" + print("Reading image") readsize = size readdata = str() while readsize > 0: @@ -273,13 +273,13 @@ class burner_socket(object): (proto_ver, pktid, rxseq, flash_addr, rxlength, data) = unpack_flash_args_fmt(in_pkt) if pktid != update_id_t.USRP2_FW_UPDATE_ID_KK_READ_TEH_FLASHES_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) readdata += data[:thisreadsize] readsize -= FLASH_DATA_PACKET_SIZE addr += FLASH_DATA_PACKET_SIZE - print "Read back %i bytes" % len(readdata) + print("Read back %i bytes" % len(readdata)) #write to disk f = open(image, 'w') @@ -293,7 +293,7 @@ class burner_socket(object): (proto_ver, pktid, rxseq, flash_addr, rxlength, data) = unpack_flash_args_fmt(in_pkt) if pktid == update_id_t.USRP2_FW_UPDATE_ID_RESETTIN_TEH_COMPUTORZ_OMG: - raise Exception, "Device failed to reset." + raise Exception("Device failed to reset.") def erase_image(self, addr, length): self._status_cb("Erasing") @@ -304,9 +304,9 @@ class burner_socket(object): (proto_ver, pktid, rxseq, flash_addr, rxlength, data) = unpack_flash_args_fmt(in_pkt) if pktid != update_id_t.USRP2_FW_UPDATE_ID_ERASING_TEH_FLASHES_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) - print "Erasing %i bytes at %i" % (length, addr) + print("Erasing %i bytes at %i" % (length, addr)) start_time = time.time() #now wait for it to finish @@ -318,7 +318,7 @@ class burner_socket(object): if pktid == update_id_t.USRP2_FW_UPDATE_ID_IM_DONE_ERASING_OMG: break elif pktid != update_id_t.USRP2_FW_UPDATE_ID_NOPE_NOT_DONE_ERASING_OMG: - raise Exception, "Invalid reply %c from device." % (chr(pktid)) + raise Exception("Invalid reply %c from device." % (chr(pktid))) time.sleep(0.01) #decrease network overhead by waiting a bit before polling self._progress_cb(min(1.0, (time.time() - start_time)/(length/80e3))) @@ -343,14 +343,14 @@ def get_options(): ######################################################################## if __name__=='__main__': options = get_options() - if not options.addr: raise Exception, 'no address specified' + if not options.addr: raise Exception('no address specified') - if not options.fpga and not options.fw and not options.reset: raise Exception, 'Must specify either a firmware image or FPGA image, and/or reset.' + if not options.fpga and not options.fw and not options.reset: raise Exception('Must specify either a firmware image or FPGA image, and/or reset.') if options.overwrite_safe and not options.read: print("Are you REALLY, REALLY sure you want to overwrite the safe image? This is ALMOST ALWAYS a terrible idea.") print("If your image is faulty, your USRP2+ will become a brick until reprogrammed via JTAG.") - response = raw_input("""Type "yes" to continue, or anything else to quit: """) + response = input("""Type "yes" to continue, or anything else to quit: """) if response != "yes": sys.exit(0) burner = burner_socket(addr=options.addr) @@ -359,7 +359,7 @@ if __name__=='__main__': if options.fw: file = options.fw if os.path.isfile(file): - response = raw_input("File already exists -- overwrite? (y/n) ") + response = input("File already exists -- overwrite? (y/n) ") if response != "y": sys.exit(0) size = FW_IMAGE_SIZE_BYTES addr = SAFE_FW_IMAGE_LOCATION_ADDR if options.overwrite_safe else PROD_FW_IMAGE_LOCATION_ADDR @@ -368,7 +368,7 @@ if __name__=='__main__': if options.fpga: file = options.fpga if os.path.isfile(file): - response = raw_input("File already exists -- overwrite? (y/n) ") + response = input("File already exists -- overwrite? (y/n) ") if response != "y": sys.exit(0) size = FPGA_IMAGE_SIZE_BYTES addr = SAFE_FPGA_IMAGE_LOCATION_ADDR if options.overwrite_safe else PROD_FPGA_IMAGE_LOCATION_ADDR diff --git a/host/utils/usrp_n2xx_net_burner_gui.py b/host/utils/usrp_n2xx_net_burner_gui.py index 7fcb7d121..50551e24a 100755..100644 --- a/host/utils/usrp_n2xx_net_burner_gui.py +++ b/host/utils/usrp_n2xx_net_burner_gui.py @@ -18,10 +18,17 @@ import threading import usrp_n2xx_net_burner #import implementation -import Tkinter, tkFileDialog, tkFont, tkMessageBox +try: + import tkinter, tkinter.filedialog, tkinter.font, tkinter.messagebox +except ImportError: + import tkFileDialog, tkFont, tkMessageBox + import Tkinter as tkinter + tkinter.filedialog = tkFileDialog + tkinter.font = tkFont + tkinter.messagebox = tkMessageBox import os -class BinFileEntry(Tkinter.Frame): +class BinFileEntry(tkinter.Frame): """ Simple file entry widget for getting the file path of bin files. Combines a label, entry, and button with file dialog callback. @@ -29,15 +36,15 @@ class BinFileEntry(Tkinter.Frame): def __init__(self, root, what, def_path=''): self._what = what - Tkinter.Frame.__init__(self, root) - Tkinter.Label(self, text=what+":").pack(side=Tkinter.LEFT) - self._entry = Tkinter.Entry(self, width=50) - self._entry.insert(Tkinter.END, def_path) - self._entry.pack(side=Tkinter.LEFT) - Tkinter.Button(self, text="...", command=self._button_cb).pack(side=Tkinter.LEFT) + tkinter.Frame.__init__(self, root) + tkinter.Label(self, text=what+":").pack(side=tkinter.LEFT) + self._entry = tkinter.Entry(self, width=50) + self._entry.insert(tkinter.END, def_path) + self._entry.pack(side=tkinter.LEFT) + tkinter.Button(self, text="...", command=self._button_cb).pack(side=tkinter.LEFT) def _button_cb(self): - filename = tkFileDialog.askopenfilename( + filename = tkinter.filedialog.askopenfilename( parent=self, filetypes=[('bin files', '*.bin'), ('all files', '*.*')], title="Select bin file for %s"%self._what, @@ -46,13 +53,13 @@ class BinFileEntry(Tkinter.Frame): # open file on your own if filename: - self._entry.delete(0, Tkinter.END) + self._entry.delete(0, tkinter.END) self._entry.insert(0, filename) def get_filename(self): return self._entry.get() -class ProgressBar(Tkinter.Canvas): +class ProgressBar(tkinter.Canvas): """ A simple implementation of a progress bar. Draws rectangle that fills from left to right. @@ -61,7 +68,7 @@ class ProgressBar(Tkinter.Canvas): def __init__(self, root, width=500, height=20): self._width = width self._height = height - Tkinter.Canvas.__init__(self, root, relief="sunken", borderwidth=2, width=self._width-2, height=self._height-2) + tkinter.Canvas.__init__(self, root, relief="sunken", borderwidth=2, width=self._width-2, height=self._height-2) self._last_fill_pixels = None self.set(0.0) @@ -78,20 +85,20 @@ class ProgressBar(Tkinter.Canvas): if frac: self.create_rectangle(0, 0, fill_pixels, self._height, fill="#357EC7") else: self.create_rectangle(0, 0, self._width, self._height, fill="#E8E8E8") -class SectionLabel(Tkinter.Label): +class SectionLabel(tkinter.Label): """ Make a text label with bold font. """ def __init__(self, root, text): - Tkinter.Label.__init__(self, root, text=text) + tkinter.Label.__init__(self, root, text=text) #set the font bold - f = tkFont.Font(font=self['font']) + f = tkinter.font.Font(font=self['font']) f['weight'] = 'bold' self['font'] = f.name -class USRPN2XXNetBurnerApp(Tkinter.Frame): +class USRPN2XXNetBurnerApp(tkinter.Frame): """ The top level gui application for the usrp-n2xx network burner. Creates entry widgets and button with callback to write images. @@ -99,7 +106,7 @@ class USRPN2XXNetBurnerApp(Tkinter.Frame): def __init__(self, root, addr, fw, fpga): - Tkinter.Frame.__init__(self, root) + tkinter.Frame.__init__(self, root) #pack the file entry widgets SectionLabel(self, text="Select Images").pack(pady=5) @@ -110,24 +117,24 @@ class USRPN2XXNetBurnerApp(Tkinter.Frame): #pack the destination entry widget SectionLabel(self, text="Select Address").pack(pady=5) - self._addr_entry = Tkinter.Entry(self, width=30) - self._addr_entry.insert(Tkinter.END, addr) + self._addr_entry = tkinter.Entry(self, width=30) + self._addr_entry.insert(tkinter.END, addr) self._addr_entry.pack() #the do it button SectionLabel(self, text="").pack(pady=5) - button = Tkinter.Button(self, text="Burn Images", command=self._burn) - self._enable_input = lambda: button.configure(state=Tkinter.NORMAL) - self._disable_input = lambda: button.configure(state=Tkinter.DISABLED) + button = tkinter.Button(self, text="Burn Images", command=self._burn) + self._enable_input = lambda: button.configure(state=tkinter.NORMAL) + self._disable_input = lambda: button.configure(state=tkinter.DISABLED) button.pack() #a progress bar to monitor the status - progress_frame = Tkinter.Frame(self) + progress_frame = tkinter.Frame(self) progress_frame.pack() - self._status = Tkinter.StringVar() - Tkinter.Label(progress_frame, textvariable=self._status).pack(side=Tkinter.LEFT) + self._status = tkinter.StringVar() + tkinter.Label(progress_frame, textvariable=self._status).pack(side=tkinter.LEFT) self._pbar = ProgressBar(progress_frame) - self._pbar.pack(side=Tkinter.RIGHT, expand=True) + self._pbar.pack(side=tkinter.RIGHT, expand=True) def _burn(self): self._disable_input() @@ -141,16 +148,16 @@ class USRPN2XXNetBurnerApp(Tkinter.Frame): #check input if not addr: - tkMessageBox.showerror('Error:', 'No address specified!') + tkinter.messagebox.showerror('Error:', 'No address specified!') return if not fw and not fpga: - tkMessageBox.showerror('Error:', 'No images specified!') + tkinter.messagebox.showerror('Error:', 'No images specified!') return if fw and not os.path.exists(fw): - tkMessageBox.showerror('Error:', 'Firmware image not found!') + tkinter.messagebox.showerror('Error:', 'Firmware image not found!') return if fpga and not os.path.exists(fpga): - tkMessageBox.showerror('Error:', 'FPGA image not found!') + tkinter.messagebox.showerror('Error:', 'FPGA image not found!') return try: @@ -165,11 +172,11 @@ class USRPN2XXNetBurnerApp(Tkinter.Frame): burner.set_callbacks(progress_cb=self._pbar.set, status_cb=status_cb) burner.burn_fw(fw=fw_img, fpga=fpga_img, reset=False, safe=False) - if tkMessageBox.askyesno("Burn was successful!", "Reset the device?"): + if tkinter.messagebox.askyesno("Burn was successful!", "Reset the device?"): burner.reset_usrp() - except Exception, e: - tkMessageBox.showerror('Verbose:', 'Error: %s'%str(e)) + except Exception as e: + tkinter.messagebox.showerror('Verbose:', 'Error: %s'%str(e)) #reset the progress bar self._pbar.set(0.0) @@ -181,7 +188,7 @@ class USRPN2XXNetBurnerApp(Tkinter.Frame): ######################################################################## if __name__=='__main__': options = usrp_n2xx_net_burner.get_options() - root = Tkinter.Tk() + root = tkinter.Tk() root.title('USRP-N2XX Net Burner') USRPN2XXNetBurnerApp(root, addr=options.addr, fw=options.fw, fpga=options.fpga).pack() root.mainloop() |