From 013aebd97ae2af3c7f1d8f0ff355a580bcd3e989 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Fri, 6 Nov 2020 10:36:31 +0000 Subject: [PATCH] Added picamera import checker --- openflexure_microscope/rescue/auto.py | 6 ++++-- openflexure_microscope/rescue/check_picamera.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 openflexure_microscope/rescue/check_picamera.py diff --git a/openflexure_microscope/rescue/auto.py b/openflexure_microscope/rescue/auto.py index 11ec6b67..08625cd2 100644 --- a/openflexure_microscope/rescue/auto.py +++ b/openflexure_microscope/rescue/auto.py @@ -6,7 +6,7 @@ from openflexure_microscope.paths import ( PREFERRED_OPENFLEXURE_VAR_PATH, ) -from . import check_capture_reload, check_settings +from . import check_capture_reload, check_settings, check_picamera # Paths for suggestions LOGS_PATHS = [ @@ -49,6 +49,7 @@ error_keys = { "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__": @@ -60,7 +61,8 @@ if __name__ == "__main__": error_sources = list(error_keys.keys()) error_sources.extend(check_settings.main()) - error_sources.extend(check_capture_reload.main()) + error_sources.extend(check_picamera.main()) + #error_sources.extend(check_capture_reload.main()) if not error_sources: diff --git a/openflexure_microscope/rescue/check_picamera.py b/openflexure_microscope/rescue/check_picamera.py new file mode 100644 index 00000000..e5f3210a --- /dev/null +++ b/openflexure_microscope/rescue/check_picamera.py @@ -0,0 +1,15 @@ +import logging + +def main(): + error_sources = [] + logging.info("Attempting to import picamera...") + + try: + from picamerax import PiCamera + except Exception as e: # pylint: disable=W0703 + # 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 + logging.error(e) + error_sources.append("picamera_import_error") + + return error_sources \ No newline at end of file