Made script executable with python3.

Added braces for compatibility with python3, should still be valid python2 which interpretes these braces as a tuple with a single element and simplifies it to that element.
Replaced whitespaces with tabs as required by python3, since indentation must be uniform (either whitespaces or tabs).
Removed trailing whitespaces.

Tested by flashing various STM32 boards with blackmagic firmware using python3.7.
This commit is contained in:
Theodor M 2019-08-29 21:05:24 +02:00 committed by UweBonnes
parent 5704c2fb5a
commit 052b5f830a
2 changed files with 55 additions and 55 deletions

View File

@ -178,16 +178,16 @@ def finddevs():
if __name__ == "__main__":
devs = finddevs()
if not devs:
print "No devices found!"
print("No devices found!")
exit(-1)
for dfu in devs:
handle = dfu[0].open()
man = handle.getString(dfu[0].iManufacturer, 30)
product = handle.getString(dfu[0].iProduct, 30)
print "Device %s: ID %04x:%04x %s - %s" % (dfu[0].filename,
dfu[0].idVendor, dfu[0].idProduct, man, product)
print "%r, %r" % (dfu[1], dfu[2])
print("Device %s: ID %04x:%04x %s - %s" % (dfu[0].filename,
dfu[0].idVendor, dfu[0].idProduct, man, product))
print("%r, %r" % (dfu[1], dfu[2]))

View File

@ -88,7 +88,7 @@ def stm32_scan(args, test):
if test == True:
return
print "No DFU devices found!"
print("No DFU devices found!")
exit(-1)
for dev in devs:
@ -101,7 +101,7 @@ def stm32_scan(args, test):
continue
man = dfudev.handle.getString(dfudev.dev.iManufacturer, 30)
if man == "Black Sphere Technologies":
if man == b"Black Sphere Technologies":
bmp = bmp + 1
bmp_devs.append(dev)
@ -109,25 +109,25 @@ def stm32_scan(args, test):
if test == True:
return
print "No compatible device found\n"
print("No compatible device found\n")
exit(-1)
if bmp > 1 and not args.serial_target:
if test == True:
return
print "Found multiple devices:\n"
print("Found multiple devices:\n")
for dev in bmp_devs:
dfudev = dfu.dfu_device(*dev)
man = dfudev.handle.getString(dfudev.dev.iManufacturer, 30)
product = dfudev.handle.getString(dfudev.dev.iProduct, 96)
serial_no = dfudev.handle.getString(dfudev.dev.iSerialNumber, 30)
print "Device ID:\t %04x:%04x" % (dfudev.dev.idVendor, dfudev.dev.idProduct)
print "Manufacturer:\t %s" % man
print "Product:\t %s" % product
print "Serial:\t\t %s\n" % serial_no
print("Device ID:\t %04x:%04x" % (dfudev.dev.idVendor, dfudev.dev.idProduct))
print("Manufacturer:\t %s" % man)
print("Product:\t %s" % product)
print("Serial:\t\t %s\n" % serial_no)
print "Select device with serial number!"
print("Select device with serial number!")
exit (-1)
for dev in bmp_devs:
@ -142,23 +142,23 @@ def stm32_scan(args, test):
if man == "Black Sphere Technologies":
break
print "Device ID:\t %04x:%04x" % (dfudev.dev.idVendor, dfudev.dev.idProduct)
print "Manufacturer:\t %s" % man
print "Product:\t %s" % product
print "Serial:\t\t %s" % serial_no
print("Device ID:\t %04x:%04x" % (dfudev.dev.idVendor, dfudev.dev.idProduct))
print("Manufacturer:\t %s" % man)
print("Product:\t %s" % product)
print("Serial:\t\t %s" % serial_no)
if args.serial_target and serial_no != args.serial_target:
print "Serial number doesn't match!\n"
print("Serial number doesn't match!\n")
exit(-2)
return dfudev
if __name__ == "__main__":
print
print "USB Device Firmware Upgrade - Host Utility -- version 1.2"
print "Copyright (C) 2011 Black Sphere Technologies"
print "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
print
print("-")
print("USB Device Firmware Upgrade - Host Utility -- version 1.2")
print("Copyright (C) 2011 Black Sphere Technologies")
print("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>")
print("-")
parser = argparse.ArgumentParser()
parser.add_argument("progfile", help="Binary file to program")
@ -171,12 +171,12 @@ if __name__ == "__main__":
state = dfudev.get_state()
except:
if args.manifest : exit(0)
print "Failed to read device state! Assuming APP_IDLE"
print("Failed to read device state! Assuming APP_IDLE")
state = dfu.STATE_APP_IDLE
if state == dfu.STATE_APP_IDLE:
dfudev.detach()
dfudev.release()
print "Invoking DFU Device"
print("Invoking DFU Device")
timeout = 0
while True :
sleep(0.5)
@ -184,11 +184,11 @@ if __name__ == "__main__":
dfudev = stm32_scan(args, True)
if dfudev: break
if timeout > 5 :
print "Error: DFU device did not appear"
print("Error: DFU device did not appear")
exit(-1)
if args.manifest :
stm32_manifest(dfudev)
print "Invoking Application Device"
print("Invoking Application Device")
exit(0)
dfudev.make_idle()
file = open(args.progfile, "rb")
@ -198,7 +198,7 @@ if __name__ == "__main__":
if args.address :
start = int(args.address, 0)
else :
if "F4" in product:
if b"F4" in product:
start = 0x8004000
else:
start = 0x8002000
@ -213,12 +213,12 @@ if __name__ == "__main__":
# get evaluated and erase called only once per sector!
stm32_erase(dfudev, addr)
except:
print "\nErase Timed out\n"
print("\nErase Timed out\n")
break
try:
stm32_set_address(dfudev, addr)
except:
print "\nSet Address Timed out\n"
print("\nSet Address Timed out\n")
break
stm32_write(dfudev, bin[:1024])
bin = bin[1024:]
@ -227,7 +227,7 @@ if __name__ == "__main__":
bin = file.read()
len = len(bin)
addr = start
print
print("-")
while bin:
try:
stm32_set_address(dfudev, addr)
@ -248,7 +248,7 @@ if __name__ == "__main__":
addr += 1024
len -= 1024
if len <= 0 :
print "\nVerified!"
print("\nVerified!")
stm32_manifest(dfudev)
print "All operations complete!\n"
print("All operations complete!\n")