Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python-2-isms and set sharpbang to use 3 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions prog/usb-flasher/usb-flash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
'''
Copyright (C) 2016 Bastille Networks

Expand All @@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''

from __future__ import print_function

import usb, time, sys, array, logging

Expand All @@ -25,32 +26,32 @@
# 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. |
------------------------------------------

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
usb_timeout = 2500

# 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
with open(sys.argv[1], 'rb') as f:
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")
Expand Down Expand Up @@ -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
Expand Down