From bb640164659ec1e9919b8ee22c2b79ad61e0fd94 Mon Sep 17 00:00:00 2001 From: Chad MILLER Date: Thu, 3 Oct 2019 22:37:32 -0700 Subject: [PATCH] Remove python-2-isms and set sharpbang to use 3 --- prog/usb-flasher/usb-flash.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/prog/usb-flasher/usb-flash.py b/prog/usb-flasher/usb-flash.py index 6f89b31..b4953d6 100755 --- a/prog/usb-flasher/usb-flash.py +++ b/prog/usb-flasher/usb-flash.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 ''' Copyright (C) 2016 Bastille Networks @@ -16,6 +16,7 @@ along with this program. If not, see . ''' +from __future__ import print_function import usb, time, sys, array, logging @@ -25,8 +26,8 @@ # Check pyusb dependency try: from usb import core as _usb_core -except ImportError, ex: - print ''' +except ImportError as ex: + print(''' ------------------------------------------ | PyUSB was not found or is out of date. | ------------------------------------------ @@ -34,7 +35,7 @@ Please update PyUSB using pip: sudo pip install -U -I pip && sudo pip install -U -I pyusb -''' +''') sys.exit(1) # USB timeout sufficiently long for operating in a VM @@ -42,7 +43,7 @@ # Verify that we received a command line argument if len(sys.argv) < 2: - print 'Usage: ./usb-flash.py path-to-firmware.bin' + print('Usage: ./usb-flash.py path-to-firmware.bin') quit() # Read in the firmware @@ -50,7 +51,7 @@ data = f.read() # Zero pad the data to a multiple of 512 bytes -data += '\000' * (512 - len(data) % 512) +data += b'\000' * (512 - len(data) % 512) # Find an attached device running CrazyRadio or RFStorm firmware logging.info("Looking for a compatible device that can jump to the Nordic bootloader") @@ -93,7 +94,7 @@ # Write the data, one page at a time logging.info("Writing image to flash") -page_count = len(data) / 512 +page_count = len(data) // 512 for page in range(page_count): # Tell the bootloader that we are going to write a page