sourcery.ai cleanup

This commit is contained in:
Romain Bazile 2020-10-27 13:43:10 +01:00
parent a5a76979b9
commit b66776a5fb
5 changed files with 22 additions and 26 deletions

View file

@ -53,6 +53,9 @@ import planktoscope.segmenter
# Import the planktonscope LED module
import planktoscope.light
# Import the planktonscope uuidName module
import planktoscope.uuidName
# global variable that keeps the wheels spinning
run = True
@ -75,18 +78,17 @@ if __name__ == "__main__":
# check if gpu_mem configuration is at least 256Meg, otherwise the camera will not run properly
with open("/boot/config.txt", "r") as config_file:
for i, line in enumerate(config_file):
if line.startswith("gpu_mem"):
if int(line.split("=")[1].strip()) < 256:
logger.error(
"The GPU memory size is less than 256, this will prevent the camera from running properly"
)
logger.error(
"Please edit the file /boot/config.txt to change the gpu_mem value to at least 256"
)
logger.error(
"or use raspi-config to change the memory split, in menu 7 Advanced Options, A3 Memory Split"
)
sys.exit(1)
if line.startswith("gpu_mem") and int(line.split("=")[1].strip()) < 256:
logger.error(
"The GPU memory size is less than 256, this will prevent the camera from running properly"
)
logger.error(
"Please edit the file /boot/config.txt to change the gpu_mem value to at least 256"
)
logger.error(
"or use raspi-config to change the memory split, in menu 7 Advanced Options, A3 Memory Split"
)
sys.exit(1)
# Let's make sure the used base path exists
img_path = "/home/pi/PlanktonScope/img"
@ -101,8 +103,7 @@ if __name__ == "__main__":
# create the path!
os.makedirs(export_path)
with open("/sys/firmware/devicetree/base/serial-number", "r") as config_file:
logger.info(f"This PlanktoScope unique ID is {config_file.readline()}")
logger.info(f"This PlanktoScope unique ID is {planktoscope.uuidName.getSerial()}")
# Prepare the event for a gracefull shutdown
shutdown_event = multiprocessing.Event()

View file

@ -280,7 +280,6 @@ class ImagerProcess(multiprocessing.Process):
logger.error("We can't update the configuration while we are imaging.")
# Publish the status "Interrupted" to via MQTT to Node-RED
self.imager_client.client.publish("status/imager", '{"status":"Busy"}')
pass
elif action == "settings":
if self.__imager.state.name is "stop":
@ -327,7 +326,6 @@ class ImagerProcess(multiprocessing.Process):
)
# Publish the status "Interrupted" to via MQTT to Node-RED
self.imager_client.client.publish("status/imager", '{"status":"Busy"}')
pass
elif action != "":
logger.warning(
@ -429,7 +427,6 @@ class ImagerProcess(multiprocessing.Process):
self.__imager.change(planktoscope.imager_state_machine.Stop)
# Set the LEDs as Green
planktoscope.light.setRGB(0, 255, 255)
return
else:
# We have not reached the final stage, let's keep imaging
# Set the LEDs as Blue
@ -459,12 +456,11 @@ class ImagerProcess(multiprocessing.Process):
# Change state towards Waiting for pump
self.__imager.change(planktoscope.imager_state_machine.Waiting)
return
elif self.__imager.state.name is "waiting":
return
elif self.__imager.state.name is "stop":
elif (
self.__imager.state.name is "waiting" or self.__imager.state.name is "stop"
):
return
################################################################################

View file

@ -84,7 +84,7 @@ def light(state):
if state == "on":
RPi.GPIO.output(21, RPi.GPIO.HIGH)
if state == "off":
elif state == "off":
RPi.GPIO.output(21, RPi.GPIO.LOW)

View file

@ -341,7 +341,6 @@ class SegmenterProcess(multiprocessing.Process):
self.segmenter_client.client.publish(
"status/segmenter", '{"status":"Busy"}'
)
pass
elif action != "":
logger.warning(

View file

@ -188,7 +188,7 @@ class StepperProcess(multiprocessing.Process):
logger.info(
"The hardware configuration file doesn't exists, using defaults"
)
configuration = dict()
configuration = {}
reverse = False
@ -371,7 +371,7 @@ class StepperProcess(multiprocessing.Process):
)
# Validation of inputs
if direction != "UP" and direction != "DOWN":
if direction not in ["UP", "DOWN"]:
logger.error("The direction command is not recognised")
logger.error("It should be either UP or DOWN")
return
@ -431,7 +431,7 @@ class StepperProcess(multiprocessing.Process):
logger.info(f"The pump will move {direction} for {volume}mL at {speed}mL/min")
# Validation of inputs
if direction != "FORWARD" and direction != "BACKWARD":
if direction not in ["FORWARD", "BACKWARD"]:
logger.error("The direction command is not recognised")
logger.error("It should be either FORWARD or BACKWARD")
return