From e6f0d8614d93f420e2f56e53452ce88dfef2da1e Mon Sep 17 00:00:00 2001 From: Yuanda Date: Sun, 11 Dec 2022 23:57:55 +0800 Subject: [PATCH 1/2] added parentheses in print --- metalWeb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metalWeb.py b/metalWeb.py index c85ccf2..6e987ee 100755 --- a/metalWeb.py +++ b/metalWeb.py @@ -39,7 +39,7 @@ if not PBR.foundChip: boards = PicoBorgRev.ScanForPicoBorgReverse() if len(boards) == 0: - print 'No PicoBorg Reverse found, check you are attached :)' + print ('No PicoBorg Reverse found, check you are attached :)') else: print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) for board in boards: From 9e3cf5621cb011363d58d1a5985aa6e39dfda237 Mon Sep 17 00:00:00 2001 From: Yuanda Date: Mon, 12 Dec 2022 00:21:58 +0800 Subject: [PATCH 2/2] Used 2to3 --- 4BorgWeb.py | 42 ++++++++++++++++++------------------ Diablo.py | 50 +++++++++++++++++++++---------------------- PicoBorgRev.py | 50 +++++++++++++++++++++---------------------- ThunderBorg.py | 50 +++++++++++++++++++++---------------------- ZeroBorg.py | 50 +++++++++++++++++++++---------------------- diabloWeb.py | 42 ++++++++++++++++++------------------ diddyRedWeb.py | 42 ++++++++++++++++++------------------ diddyWeb.py | 42 ++++++++++++++++++------------------ metalWeb.py | 40 +++++++++++++++++----------------- metalWebv2.py | 58 +++++++++++++++++++++++++------------------------- monsterWeb.py | 54 +++++++++++++++++++++++----------------------- yetiWeb.py | 42 ++++++++++++++++++------------------ 12 files changed, 281 insertions(+), 281 deletions(-) diff --git a/4BorgWeb.py b/4BorgWeb.py index 6740ef2..cb007c6 100755 --- a/4BorgWeb.py +++ b/4BorgWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -39,13 +39,13 @@ if not PBR.foundChip: boards = PicoBorgRev.ScanForPicoBorgReverse() if len(boards) == 0: - print 'No PicoBorg Reverse found, check you are attached :)' + print('No PicoBorg Reverse found, check you are attached :)') else: - print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) + print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'PBR.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('PBR.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper PBR.SetCommsFailsafe(False) # Disable the communications failsafe @@ -78,7 +78,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -86,7 +86,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True PBR.MotorsOff() @@ -131,12 +131,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -149,7 +149,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global PBR global lastFrame @@ -465,34 +465,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios PBR.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -502,4 +502,4 @@ def send(self, content): watchdog.join() del camera PBR.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/Diablo.py b/Diablo.py index e39dfb7..b8f4ce7 100644 --- a/Diablo.py +++ b/Diablo.py @@ -85,7 +85,7 @@ def ScanForDiablo(busNumber = 1): The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1 """ found = [] - print 'Scanning I�C bus #%d' % (busNumber) + print(('Scanning I�C bus #%d' % (busNumber))) bus = Diablo() for address in range(0x03, 0x78, 1): try: @@ -93,7 +93,7 @@ def ScanForDiablo(busNumber = 1): i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_DIABLO: - print 'Found Diablo at %02X' % (address) + print(('Found Diablo at %02X' % (address))) found.append(address) else: pass @@ -104,11 +104,11 @@ def ScanForDiablo(busNumber = 1): except: pass if len(found) == 0: - print 'No Diablo boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber) + print(('No Diablo boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber))) elif len(found) == 1: - print '1 Diablo board found' + print('1 Diablo board found') else: - print '%d Diablo boards found' % (len(found)) + print(('%d Diablo boards found' % (len(found)))) return found @@ -122,19 +122,19 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): Warning, this new I�C address will still be used after resetting the power on the device """ if newAddress < 0x03: - print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)') return elif newAddress > 0x77: - print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)') return if oldAddress < 0x0: found = ScanForDiablo(busNumber) if len(found) < 1: - print 'No Diablo boards found, cannot set a new I�C address!' + print('No Diablo boards found, cannot set a new I�C address!') return else: oldAddress = found[0] - print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber) + print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber))) bus = Diablo() bus.InitBusOnly(busNumber, oldAddress) try: @@ -142,44 +142,44 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_DIABLO: foundChip = True - print 'Found Diablo at %02X' % (oldAddress) + print(('Found Diablo at %02X' % (oldAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_DIABLO) + print(('Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_DIABLO))) else: foundChip = False - print 'Missing Diablo at %02X' % (oldAddress) + print(('Missing Diablo at %02X' % (oldAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing Diablo at %02X' % (oldAddress) + print(('Missing Diablo at %02X' % (oldAddress))) if foundChip: bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress]) time.sleep(0.1) - print 'Address changed to %02X, attempting to talk with the new address' % (newAddress) + print(('Address changed to %02X, attempting to talk with the new address' % (newAddress))) try: bus.InitBusOnly(busNumber, newAddress) i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_DIABLO: foundChip = True - print 'Found Diablo at %02X' % (newAddress) + print(('Found Diablo at %02X' % (newAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_DIABLO) + print(('Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_DIABLO))) else: foundChip = False - print 'Missing Diablo at %02X' % (newAddress) + print(('Missing Diablo at %02X' % (newAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing Diablo at %02X' % (newAddress) + print(('Missing Diablo at %02X' % (newAddress))) if foundChip: - print 'New I�C address of %02X set successfully' % (newAddress) + print(('New I�C address of %02X set successfully' % (newAddress))) else: - print 'Failed to set new I�C address...' + print('Failed to set new I�C address...') # Class used to control Diablo @@ -268,7 +268,7 @@ def Print(self, message): Wrapper used by the Diablo instance to print messages, will call printFunction if set, print otherwise """ if self.printFunction == None: - print message + print(message) else: self.printFunction(message) @@ -904,10 +904,10 @@ def Help(self): Displays the names and descriptions of the various functions and settings provided """ funcList = [Diablo.__dict__.get(a) for a in dir(Diablo) if isinstance(Diablo.__dict__.get(a), types.FunctionType)] - funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno) + funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno) - print self.__doc__ - print + print((self.__doc__)) + print() for func in funcListSorted: - print '=== %s === %s' % (func.func_name, func.func_doc) + print(('=== %s === %s' % (func.__name__, func.__doc__))) diff --git a/PicoBorgRev.py b/PicoBorgRev.py index 8ecde69..63c7e7e 100755 --- a/PicoBorgRev.py +++ b/PicoBorgRev.py @@ -86,7 +86,7 @@ def ScanForPicoBorgReverse(busNumber = 1): The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1 """ found = [] - print 'Scanning I�C bus #%d' % (busNumber) + print(('Scanning I�C bus #%d' % (busNumber))) bus = PicoBorgRev() for address in range(0x03, 0x78, 1): try: @@ -94,7 +94,7 @@ def ScanForPicoBorgReverse(busNumber = 1): i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_PICOBORG_REV: - print 'Found PicoBorg Reverse at %02X' % (address) + print(('Found PicoBorg Reverse at %02X' % (address))) found.append(address) else: pass @@ -105,11 +105,11 @@ def ScanForPicoBorgReverse(busNumber = 1): except: pass if len(found) == 0: - print 'No PicoBorg Reverse boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber) + print(('No PicoBorg Reverse boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber))) elif len(found) == 1: - print '1 PicoBorg Reverse board found' + print('1 PicoBorg Reverse board found') else: - print '%d PicoBorg Reverse boards found' % (len(found)) + print(('%d PicoBorg Reverse boards found' % (len(found)))) return found @@ -123,19 +123,19 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): Warning, this new I�C address will still be used after resetting the power on the device """ if newAddress < 0x03: - print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)') return elif newAddress > 0x77: - print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)') return if oldAddress < 0x0: found = ScanForPicoBorgReverse(busNumber) if len(found) < 1: - print 'No PicoBorg Reverse boards found, cannot set a new I�C address!' + print('No PicoBorg Reverse boards found, cannot set a new I�C address!') return else: oldAddress = found[0] - print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber) + print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber))) bus = PicoBorgRev() bus.InitBusOnly(busNumber, oldAddress) try: @@ -143,44 +143,44 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_PICOBORG_REV: foundChip = True - print 'Found PicoBorg Reverse at %02X' % (oldAddress) + print(('Found PicoBorg Reverse at %02X' % (oldAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_PICOBORG_REV) + print(('Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_PICOBORG_REV))) else: foundChip = False - print 'Missing PicoBorg Reverse at %02X' % (oldAddress) + print(('Missing PicoBorg Reverse at %02X' % (oldAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing PicoBorg Reverse at %02X' % (oldAddress) + print(('Missing PicoBorg Reverse at %02X' % (oldAddress))) if foundChip: bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress]) time.sleep(0.1) - print 'Address changed to %02X, attempting to talk with the new address' % (newAddress) + print(('Address changed to %02X, attempting to talk with the new address' % (newAddress))) try: bus.InitBusOnly(busNumber, newAddress) i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_PICOBORG_REV: foundChip = True - print 'Found PicoBorg Reverse at %02X' % (newAddress) + print(('Found PicoBorg Reverse at %02X' % (newAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_PICOBORG_REV) + print(('Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_PICOBORG_REV))) else: foundChip = False - print 'Missing PicoBorg Reverse at %02X' % (newAddress) + print(('Missing PicoBorg Reverse at %02X' % (newAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing PicoBorg Reverse at %02X' % (newAddress) + print(('Missing PicoBorg Reverse at %02X' % (newAddress))) if foundChip: - print 'New I�C address of %02X set successfully' % (newAddress) + print(('New I�C address of %02X set successfully' % (newAddress))) else: - print 'Failed to set new I�C address...' + print('Failed to set new I�C address...') # Class used to control PicoBorg Reverse @@ -269,7 +269,7 @@ def Print(self, message): Wrapper used by the PicoBorgRev instance to print messages, will call printFunction if set, print otherwise """ if self.printFunction == None: - print message + print(message) else: self.printFunction(message) @@ -935,10 +935,10 @@ def Help(self): Displays the names and descriptions of the various functions and settings provided """ funcList = [PicoBorgRev.__dict__.get(a) for a in dir(PicoBorgRev) if isinstance(PicoBorgRev.__dict__.get(a), types.FunctionType)] - funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno) + funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno) - print self.__doc__ - print + print((self.__doc__)) + print() for func in funcListSorted: - print '=== %s === %s' % (func.func_name, func.func_doc) + print(('=== %s === %s' % (func.__name__, func.__doc__))) diff --git a/ThunderBorg.py b/ThunderBorg.py index 1c1f950..f316436 100755 --- a/ThunderBorg.py +++ b/ThunderBorg.py @@ -87,7 +87,7 @@ def ScanForThunderBorg(busNumber = 1): The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1 """ found = [] - print 'Scanning I�C bus #%d' % (busNumber) + print(('Scanning I�C bus #%d' % (busNumber))) bus = ThunderBorg() for address in range(0x03, 0x78, 1): try: @@ -95,7 +95,7 @@ def ScanForThunderBorg(busNumber = 1): i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_THUNDERBORG: - print 'Found ThunderBorg at %02X' % (address) + print(('Found ThunderBorg at %02X' % (address))) found.append(address) else: pass @@ -106,11 +106,11 @@ def ScanForThunderBorg(busNumber = 1): except: pass if len(found) == 0: - print 'No ThunderBorg boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber) + print(('No ThunderBorg boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber))) elif len(found) == 1: - print '1 ThunderBorg board found' + print('1 ThunderBorg board found') else: - print '%d ThunderBorg boards found' % (len(found)) + print(('%d ThunderBorg boards found' % (len(found)))) return found @@ -124,19 +124,19 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): Warning, this new I�C address will still be used after resetting the power on the device """ if newAddress < 0x03: - print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)') return elif newAddress > 0x77: - print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)') return if oldAddress < 0x0: found = ScanForThunderBorg(busNumber) if len(found) < 1: - print 'No ThunderBorg boards found, cannot set a new I�C address!' + print('No ThunderBorg boards found, cannot set a new I�C address!') return else: oldAddress = found[0] - print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber) + print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber))) bus = ThunderBorg() bus.InitBusOnly(busNumber, oldAddress) try: @@ -144,44 +144,44 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_THUNDERBORG: foundChip = True - print 'Found ThunderBorg at %02X' % (oldAddress) + print(('Found ThunderBorg at %02X' % (oldAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a ThunderBorg (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_THUNDERBORG) + print(('Found a device at %02X, but it is not a ThunderBorg (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_THUNDERBORG))) else: foundChip = False - print 'Missing ThunderBorg at %02X' % (oldAddress) + print(('Missing ThunderBorg at %02X' % (oldAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing ThunderBorg at %02X' % (oldAddress) + print(('Missing ThunderBorg at %02X' % (oldAddress))) if foundChip: bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress]) time.sleep(0.1) - print 'Address changed to %02X, attempting to talk with the new address' % (newAddress) + print(('Address changed to %02X, attempting to talk with the new address' % (newAddress))) try: bus.InitBusOnly(busNumber, newAddress) i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN) if len(i2cRecv) == I2C_MAX_LEN: if i2cRecv[1] == I2C_ID_THUNDERBORG: foundChip = True - print 'Found ThunderBorg at %02X' % (newAddress) + print(('Found ThunderBorg at %02X' % (newAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a ThunderBorg (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_THUNDERBORG) + print(('Found a device at %02X, but it is not a ThunderBorg (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_THUNDERBORG))) else: foundChip = False - print 'Missing ThunderBorg at %02X' % (newAddress) + print(('Missing ThunderBorg at %02X' % (newAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing ThunderBorg at %02X' % (newAddress) + print(('Missing ThunderBorg at %02X' % (newAddress))) if foundChip: - print 'New I�C address of %02X set successfully' % (newAddress) + print(('New I�C address of %02X set successfully' % (newAddress))) else: - print 'Failed to set new I�C address...' + print('Failed to set new I�C address...') # Class used to control ThunderBorg @@ -270,7 +270,7 @@ def Print(self, message): Wrapper used by the ThunderBorg instance to print messages, will call printFunction if set, print otherwise """ if self.printFunction == None: - print message + print(message) else: self.printFunction(message) @@ -899,10 +899,10 @@ def Help(self): Displays the names and descriptions of the various functions and settings provided """ funcList = [ThunderBorg.__dict__.get(a) for a in dir(ThunderBorg) if isinstance(ThunderBorg.__dict__.get(a), types.FunctionType)] - funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno) + funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno) - print self.__doc__ - print + print((self.__doc__)) + print() for func in funcListSorted: - print '=== %s === %s' % (func.func_name, func.func_doc) + print(('=== %s === %s' % (func.__name__, func.__doc__))) diff --git a/ZeroBorg.py b/ZeroBorg.py index 25a6f9a..939ce41 100755 --- a/ZeroBorg.py +++ b/ZeroBorg.py @@ -90,7 +90,7 @@ def ScanForZeroBorg(busNumber = 1): The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1 """ found = [] - print 'Scanning I�C bus #%d' % (busNumber) + print(('Scanning I�C bus #%d' % (busNumber))) bus = ZeroBorg() for address in range(0x03, 0x78, 1): try: @@ -98,7 +98,7 @@ def ScanForZeroBorg(busNumber = 1): i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_NORM_LEN) if len(i2cRecv) == I2C_NORM_LEN: if i2cRecv[1] == I2C_ID_ZEROBORG: - print 'Found ZeroBorg at %02X' % (address) + print(('Found ZeroBorg at %02X' % (address))) found.append(address) else: pass @@ -109,11 +109,11 @@ def ScanForZeroBorg(busNumber = 1): except: pass if len(found) == 0: - print 'No ZeroBorg boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber) + print(('No ZeroBorg boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber))) elif len(found) == 1: - print '1 ZeroBorg board found' + print('1 ZeroBorg board found') else: - print '%d ZeroBorg boards found' % (len(found)) + print(('%d ZeroBorg boards found' % (len(found)))) return found @@ -127,19 +127,19 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): Warning, this new I�C address will still be used after resetting the power on the device """ if newAddress < 0x03: - print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)') return elif newAddress > 0x77: - print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)' + print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)') return if oldAddress < 0x0: found = ScanForZeroBorg(busNumber) if len(found) < 1: - print 'No ZeroBorg boards found, cannot set a new I�C address!' + print('No ZeroBorg boards found, cannot set a new I�C address!') return else: oldAddress = found[0] - print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber) + print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber))) bus = ZeroBorg() bus.InitBusOnly(busNumber, oldAddress) try: @@ -147,44 +147,44 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1): if len(i2cRecv) == I2C_NORM_LEN: if i2cRecv[1] == I2C_ID_ZEROBORG: foundChip = True - print 'Found ZeroBorg at %02X' % (oldAddress) + print(('Found ZeroBorg at %02X' % (oldAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a ZeroBorg (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_ZEROBORG) + print(('Found a device at %02X, but it is not a ZeroBorg (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_ZEROBORG))) else: foundChip = False - print 'Missing ZeroBorg at %02X' % (oldAddress) + print(('Missing ZeroBorg at %02X' % (oldAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing ZeroBorg at %02X' % (oldAddress) + print(('Missing ZeroBorg at %02X' % (oldAddress))) if foundChip: bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress]) time.sleep(0.1) - print 'Address changed to %02X, attempting to talk with the new address' % (newAddress) + print(('Address changed to %02X, attempting to talk with the new address' % (newAddress))) try: bus.InitBusOnly(busNumber, newAddress) i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_NORM_LEN) if len(i2cRecv) == I2C_NORM_LEN: if i2cRecv[1] == I2C_ID_ZEROBORG: foundChip = True - print 'Found ZeroBorg at %02X' % (newAddress) + print(('Found ZeroBorg at %02X' % (newAddress))) else: foundChip = False - print 'Found a device at %02X, but it is not a ZeroBorg (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_ZEROBORG) + print(('Found a device at %02X, but it is not a ZeroBorg (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_ZEROBORG))) else: foundChip = False - print 'Missing ZeroBorg at %02X' % (newAddress) + print(('Missing ZeroBorg at %02X' % (newAddress))) except KeyboardInterrupt: raise except: foundChip = False - print 'Missing ZeroBorg at %02X' % (newAddress) + print(('Missing ZeroBorg at %02X' % (newAddress))) if foundChip: - print 'New I�C address of %02X set successfully' % (newAddress) + print(('New I�C address of %02X set successfully' % (newAddress))) else: - print 'Failed to set new I�C address...' + print('Failed to set new I�C address...') # Class used to control ZeroBorg @@ -273,7 +273,7 @@ def Print(self, message): Wrapper used by the ZeroBorg instance to print messages, will call printFunction if set, print otherwise """ if self.printFunction == None: - print message + print(message) else: self.printFunction(message) @@ -920,10 +920,10 @@ def Help(self): Displays the names and descriptions of the various functions and settings provided """ funcList = [ZeroBorg.__dict__.get(a) for a in dir(ZeroBorg) if isinstance(ZeroBorg.__dict__.get(a), types.FunctionType)] - funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno) + funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno) - print self.__doc__ - print + print((self.__doc__)) + print() for func in funcListSorted: - print '=== %s === %s' % (func.func_name, func.func_doc) + print(('=== %s === %s' % (func.__name__, func.__doc__))) diff --git a/diabloWeb.py b/diabloWeb.py index 2d1482b..b5dfce4 100644 --- a/diabloWeb.py +++ b/diabloWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -39,13 +39,13 @@ if not DIABLO.foundChip: boards = Diablo.ScanForDiablo() if len(boards) == 0: - print 'No Diablo found, check you are attached :)' + print('No Diablo found, check you are attached :)') else: - print 'No Diablo at address %02X, but we did find boards:' % (DIABLO.i2cAddress) + print(('No Diablo at address %02X, but we did find boards:' % (DIABLO.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I�C address change the setup line so it is correct, e.g.' - print 'DIABLO.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I�C address change the setup line so it is correct, e.g.') + print(('DIABLO.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #DIABLO.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper DIABLO.ResetEpo() @@ -77,7 +77,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -85,7 +85,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True DIABLO.MotorsOff() @@ -130,12 +130,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -148,7 +148,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global DIABLO global lastFrame @@ -464,34 +464,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios DIABLO.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -500,4 +500,4 @@ def send(self, content): processor.join() watchdog.join() del camera -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/diddyRedWeb.py b/diddyRedWeb.py index b40fcf6..ed70df7 100755 --- a/diddyRedWeb.py +++ b/diddyRedWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -39,13 +39,13 @@ if not PBR.foundChip: boards = PicoBorgRev.ScanForPicoBorgReverse() if len(boards) == 0: - print 'No PicoBorg Reverse found, check you are attached :)' + print('No PicoBorg Reverse found, check you are attached :)') else: - print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) + print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'PBR.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('PBR.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper PBR.SetCommsFailsafe(False) # Disable the communications failsafe @@ -78,7 +78,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -86,7 +86,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True PBR.MotorsOff() @@ -131,12 +131,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -149,7 +149,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global PBR global lastFrame @@ -465,34 +465,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios PBR.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -502,4 +502,4 @@ def send(self, content): watchdog.join() del camera PBR.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/diddyWeb.py b/diddyWeb.py index 42581e8..f471ec1 100755 --- a/diddyWeb.py +++ b/diddyWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -39,13 +39,13 @@ if not PBR.foundChip: boards = PicoBorgRev.ScanForPicoBorgReverse() if len(boards) == 0: - print 'No PicoBorg Reverse found, check you are attached :)' + print('No PicoBorg Reverse found, check you are attached :)') else: - print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) + print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'PBR.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('PBR.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper PBR.SetCommsFailsafe(False) # Disable the communications failsafe @@ -78,7 +78,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -86,7 +86,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True PBR.MotorsOff() @@ -131,12 +131,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -149,7 +149,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global PBR global lastFrame @@ -465,34 +465,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios PBR.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -502,4 +502,4 @@ def send(self, content): watchdog.join() del camera PBR.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/metalWeb.py b/metalWeb.py index 6e987ee..9375652 100755 --- a/metalWeb.py +++ b/metalWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -41,11 +41,11 @@ if len(boards) == 0: print ('No PicoBorg Reverse found, check you are attached :)') else: - print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) + print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'PBR.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print ('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('PBR.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper PBR.SetCommsFailsafe(False) # Disable the communications failsafe @@ -78,7 +78,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print ('Reconnected...') timedOut = False self.event.clear() else: @@ -86,7 +86,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True PBR.MotorsOff() @@ -131,12 +131,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -149,7 +149,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global PBR global lastFrame @@ -465,34 +465,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios PBR.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -502,4 +502,4 @@ def send(self, content): watchdog.join() del camera PBR.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/metalWebv2.py b/metalWebv2.py index 2cf4021..336d473 100644 --- a/metalWebv2.py +++ b/metalWebv2.py @@ -11,7 +11,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -56,13 +56,13 @@ if not PBR.foundChip: boards = PicoBorgRev.ScanForPicoBorgReverse() if len(boards) == 0: - print 'No PicoBorg Reverse found, check you are attached :)' + print('No PicoBorg Reverse found, check you are attached :)') else: - print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress) + print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'PBR.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('PBR.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper PBR.SetCommsFailsafe(False) # Disable the communications failsafe @@ -95,7 +95,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -103,7 +103,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True PBR.MotorsOff() @@ -148,12 +148,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -229,11 +229,11 @@ def run(self): thread.sleep(0.2) else: # Unexpected, print an error and wait a second before trying again - print 'Unexpected movement mode %d' % (movementMode) + print(('Unexpected movement mode %d' % (movementMode))) time.sleep(1.0) # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global PBR global lastFrame @@ -702,49 +702,49 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() -print 'Setup the automatic movement' +print('Setup the automatic movement') autoMovement = AutoMovement() # Run the web server until we are told to close try: httpServer = None - httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) + httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) except: # Failed to open the port, report common issues - print - print 'Failed to open port %d' % (webPort) - print 'Make sure you are running the script with sudo permissions' - print 'Other problems include running another script with the same port' - print 'If the script was just working recently try waiting a minute first' - print + print() + print(('Failed to open port %d' % (webPort))) + print('Make sure you are running the script with sudo permissions') + print('Other problems include running another script with the same port') + print('If the script was just working recently try waiting a minute first') + print() # Flag the script to exit running = False try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios PBR.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -756,4 +756,4 @@ def send(self, content): autoMovement.join() del camera PBR.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/monsterWeb.py b/monsterWeb.py index 43bfa98..7b6c0ba 100755 --- a/monsterWeb.py +++ b/monsterWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -40,13 +40,13 @@ if not TB.foundChip: boards = ThunderBorg.ScanForThunderBorg() if len(boards) == 0: - print 'No ThunderBorg found, check you are attached :)' + print('No ThunderBorg found, check you are attached :)') else: - print 'No ThunderBorg at address %02X, but we did find boards:' % (TB.i2cAddress) + print(('No ThunderBorg at address %02X, but we did find boards:' % (TB.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I�C address change the setup line so it is correct, e.g.' - print 'TB.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I�C address change the setup line so it is correct, e.g.') + print(('TB.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() TB.SetCommsFailsafe(False) TB.SetLedShowBattery(False) @@ -79,7 +79,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') TB.SetLedShowBattery(True) timedOut = False self.event.clear() @@ -88,7 +88,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') TB.SetLedShowBattery(False) TB.SetLeds(0,0,1) timedOut = True @@ -138,12 +138,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -156,7 +156,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global TB global lastFrame @@ -472,46 +472,46 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close try: httpServer = None - httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) + httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) except: # Failed to open the port, report common issues - print - print 'Failed to open port %d' % (webPort) - print 'Make sure you are running the script with sudo permissions' - print 'Other problems include running another script with the same port' - print 'If the script was just working recently try waiting a minute first' - print + print() + print(('Failed to open port %d' % (webPort))) + print('Make sure you are running the script with sudo permissions') + print('Other problems include running another script with the same port') + print('If the script was just working recently try waiting a minute first') + print() # Flag the script to exit running = False try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios TB.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end if httpServer != None: httpServer.server_close() @@ -525,6 +525,6 @@ def send(self, content): TB.SetLedShowBattery(False) TB.SetLeds(0,0,0) TB.MotorsOff() -print 'Web-server terminated.' +print('Web-server terminated.') diff --git a/yetiWeb.py b/yetiWeb.py index 3b92fb0..15764d5 100755 --- a/yetiWeb.py +++ b/yetiWeb.py @@ -8,7 +8,7 @@ import time import sys import threading -import SocketServer +import socketserver import picamera import picamera.array import cv2 @@ -39,13 +39,13 @@ if not ZB.foundChip: boards = ZeroBorg.ScanForZeroBorg() if len(boards) == 0: - print 'No ZeroBorg found, check you are attached :)' + print('No ZeroBorg found, check you are attached :)') else: - print 'No ZeroBorg at address %02X, but we did find boards:' % (ZB.i2cAddress) + print(('No ZeroBorg at address %02X, but we did find boards:' % (ZB.i2cAddress))) for board in boards: - print ' %02X (%d)' % (board, board) - print 'If you need to change the I²C address change the setup line so it is correct, e.g.' - print 'ZB.i2cAddress = 0x%02X' % (boards[0]) + print((' %02X (%d)' % (board, board))) + print('If you need to change the I²C address change the setup line so it is correct, e.g.') + print(('ZB.i2cAddress = 0x%02X' % (boards[0]))) sys.exit() #ZB.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper ZB.SetCommsFailsafe(False) @@ -79,7 +79,7 @@ def run(self): if timedOut: if self.event.wait(1): # Connection - print 'Reconnected...' + print('Reconnected...') timedOut = False self.event.clear() else: @@ -87,7 +87,7 @@ def run(self): self.event.clear() else: # Timed out - print 'Timed out...' + print('Timed out...') timedOut = True ZB.MotorsOff() @@ -132,12 +132,12 @@ def __init__(self): def run(self): global camera global processor - print 'Start the stream using the video port' + print('Start the stream using the video port') camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True) - print 'Terminating camera processing...' + print('Terminating camera processing...') processor.terminated = True processor.join() - print 'Processing terminated.' + print('Processing terminated.') # Stream delegation loop def TriggerStream(self): @@ -150,7 +150,7 @@ def TriggerStream(self): processor.event.set() # Class used to implement the web server -class WebServer(SocketServer.BaseRequestHandler): +class WebServer(socketserver.BaseRequestHandler): def handle(self): global ZB global lastFrame @@ -353,34 +353,34 @@ def send(self, content): lockFrame = threading.Lock() # Startup sequence -print 'Setup camera' +print('Setup camera') camera = picamera.PiCamera() camera.resolution = (imageWidth, imageHeight) camera.framerate = frameRate -print 'Setup the stream processing thread' +print('Setup the stream processing thread') processor = StreamProcessor() -print 'Wait ...' +print('Wait ...') time.sleep(2) captureThread = ImageCapture() -print 'Setup the watchdog' +print('Setup the watchdog') watchdog = Watchdog() # Run the web server until we are told to close -httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer) +httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer) try: - print 'Press CTRL+C to terminate the web-server' + print('Press CTRL+C to terminate the web-server') while running: httpServer.handle_request() except KeyboardInterrupt: # CTRL+C exit - print '\nUser shutdown' + print('\nUser shutdown') finally: # Turn the motors off under all scenarios ZB.MotorsOff() - print 'Motors off' + print('Motors off') # Tell each thread to stop, and wait for them to end running = False captureThread.join() @@ -390,4 +390,4 @@ def send(self, content): watchdog.join() del camera ZB.SetLed(True) -print 'Web-server terminated.' +print('Web-server terminated.')