Added stage tests and tidied up rescue
This commit is contained in:
parent
70437212b1
commit
0989a50558
4 changed files with 69 additions and 36 deletions
|
|
@ -1,12 +1,15 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from .error_sources import bcolors
|
||||||
|
|
||||||
from openflexure_microscope.paths import (
|
from openflexure_microscope.paths import (
|
||||||
FALLBACK_OPENFLEXURE_VAR_PATH,
|
FALLBACK_OPENFLEXURE_VAR_PATH,
|
||||||
PREFERRED_OPENFLEXURE_VAR_PATH,
|
PREFERRED_OPENFLEXURE_VAR_PATH,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import check_capture_reload, check_settings, check_picamera
|
from . import check_capture_reload, check_settings, check_picamera, check_sangaboard
|
||||||
|
|
||||||
# Paths for suggestions
|
# Paths for suggestions
|
||||||
LOGS_PATHS = [
|
LOGS_PATHS = [
|
||||||
|
|
@ -26,38 +29,26 @@ DATA_PATHS = [
|
||||||
os.path.join(FALLBACK_OPENFLEXURE_VAR_PATH, "data"),
|
os.path.join(FALLBACK_OPENFLEXURE_VAR_PATH, "data"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Look for debug flag
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
if "-d" in sys.argv or "--debug" in sys.argv:
|
||||||
logging.debug("Testing debug logger. One two one two.")
|
logger.setLevel(logging.DEBUG)
|
||||||
|
logging.debug("Testing debug logger. One two one two.")
|
||||||
|
else:
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
error_keys = {
|
|
||||||
"config_settings_import_error": "The configuration submodule could not be imported properly. This is usually because the default config or settings files are badly broken somehow. See further errors for details",
|
|
||||||
"default_config_empty": "The default configuration file is empty, and could not be automatically populated.",
|
|
||||||
"default_settings_empty": "The default settings file is empty, and could not be automatically populated.",
|
|
||||||
"default_config_error": f"The default configuration file could not be parsed. To fix, consider backing up and deleting your configuration files from {CONFIG_PATHS} to reset the configuration.",
|
|
||||||
"default_settings_error": f"The default settings file could not be parsed. To fix, consider backing up and deleting your configuration files from {SETTINGS_PATHS} to reset the configuration.",
|
|
||||||
"capture_rebuild_timeout": f"Capture database rebuilding took a long time. This may not cause catastrophic errors, but rather will cause the server to hang for a while. To fix, consider moving your captures from {DATA_PATHS} to another location.",
|
|
||||||
"picamera_import_error": "Picamera module could not be imported. Check physical connections to the camera as it may be damaged.",
|
|
||||||
}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
spoof = False
|
spoof = False
|
||||||
|
|
||||||
error_sources = []
|
error_sources = []
|
||||||
|
|
||||||
if spoof:
|
|
||||||
error_sources = list(error_keys.keys())
|
|
||||||
|
|
||||||
error_sources.extend(check_settings.main())
|
error_sources.extend(check_settings.main())
|
||||||
error_sources.extend(check_picamera.main())
|
error_sources.extend(check_picamera.main())
|
||||||
# error_sources.extend(check_capture_reload.main())
|
error_sources.extend(check_capture_reload.main())
|
||||||
|
error_sources.extend(check_sangaboard.main())
|
||||||
|
|
||||||
if not error_sources:
|
if not error_sources:
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print(bcolors.OKGREEN + "No errors found!" + bcolors.ENDC)
|
print(bcolors.OKGREEN + "No errors found!" + bcolors.ENDC)
|
||||||
print(
|
print(
|
||||||
|
|
@ -66,7 +57,6 @@ if __name__ == "__main__":
|
||||||
print(f"You can check through the server logs at {LOGS_PATHS}")
|
print(f"You can check through the server logs at {LOGS_PATHS}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for err_code in error_sources:
|
print()
|
||||||
logging.error(err_code)
|
for err in error_sources:
|
||||||
if error_keys.get(err_code):
|
print(err.message)
|
||||||
print(bcolors.FAIL + error_keys.get(err_code) + bcolors.ENDC)
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from .error_sources import ErrorSource, WarningSource
|
||||||
|
|
||||||
|
picamera_import_error = ErrorSource(
|
||||||
|
"Picamera module could not be imported. Check physical connections to the camera as it may be damaged."
|
||||||
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
error_sources = []
|
error_sources = []
|
||||||
|
|
@ -11,6 +16,6 @@ def main():
|
||||||
# TODO: Parse exception object for a few different issues, and append different error sources
|
# TODO: Parse exception object for a few different issues, and append different error sources
|
||||||
# E.g. pi with camera already in use, disconnected, unsupported OS, etc
|
# E.g. pi with camera already in use, disconnected, unsupported OS, etc
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
error_sources.append("picamera_import_error")
|
error_sources.append(picamera_import_error)
|
||||||
|
|
||||||
return error_sources
|
return error_sources
|
||||||
|
|
|
||||||
44
openflexure_microscope/rescue/check_sangaboard.py
Normal file
44
openflexure_microscope/rescue/check_sangaboard.py
Normal 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
|
||||||
|
|
@ -18,19 +18,13 @@ class Source:
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
|
|
||||||
class WarningSource:
|
class WarningSource(Source):
|
||||||
def __init__(self, message):
|
|
||||||
self.message = message
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
print(bcolors.WARNING + self._message + bcolors.ENDC)
|
return bcolors.WARNING + self._message + bcolors.ENDC
|
||||||
|
|
||||||
|
|
||||||
class ErrorSource:
|
class ErrorSource(Source):
|
||||||
def __init__(self, message):
|
|
||||||
self.message = message
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
print(bcolors.FAIL + self._message + bcolors.ENDC)
|
return bcolors.FAIL + self._message + bcolors.ENDC
|
||||||
Loading…
Add table
Add a link
Reference in a new issue