Added stage tests and tidied up rescue

This commit is contained in:
Joel Collins 2020-11-06 15:34:34 +00:00
parent 70437212b1
commit 0989a50558
4 changed files with 69 additions and 36 deletions

View file

@ -0,0 +1,44 @@
from .error_sources import ErrorSource, WarningSource
from openflexure_microscope.config import user_configuration
def main():
error_sources = []
try:
from sangaboard import Sangaboard
except Exception as e: # pylint: disable=W0703
error_sources.append(ErrorSource(
"Sangaboard module could not be imported."
))
else:
configuration = user_configuration.load()
stage_type = configuration["stage"].get("type")
stage_port = configuration["stage"].get("port")
error_sources.append(WarningSource(
"Stage serial port is not specified in configuration. Application will scan ports for a Sangaboard."
))
# If any Sangaboard-based stage is configured for use
if stage_type in ("SangaBoard", "SangaStage", "SangaDeltaStage"):
# Try connecting on the specified port
try:
_ = Sangaboard(stage_port)
except FileNotFoundError as e: # pylint: disable=W0703
if stage_port:
error_sources.append(ErrorSource(
f"No {stage_type} device was found on the configured port {stage_port}."
))
else:
error_sources.append(ErrorSource(
f"No {stage_type} device was found during port scanning."
))
else:
error_sources.append(ErrorSource(
f"Invalid stage type {stage_type} specified in configuration file."
))
return error_sources