From 70437212b120c379d8485b592b5589034316f0de Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Fri, 6 Nov 2020 12:19:41 +0000 Subject: [PATCH] Added classes for error sources --- openflexure_microscope/rescue/auto.py | 14 ++------ .../rescue/check_picamera.py | 3 +- .../rescue/error_sources.py | 36 +++++++++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 openflexure_microscope/rescue/error_sources.py diff --git a/openflexure_microscope/rescue/auto.py b/openflexure_microscope/rescue/auto.py index 08625cd2..b092a366 100644 --- a/openflexure_microscope/rescue/auto.py +++ b/openflexure_microscope/rescue/auto.py @@ -31,15 +31,7 @@ logger.setLevel(logging.DEBUG) logging.debug("Testing debug logger. One two one two.") -class bcolors: - HEADER = "\033[95m" - OKBLUE = "\033[94m" - OKGREEN = "\033[92m" - WARNING = "\033[93m" - FAIL = "\033[91m" - ENDC = "\033[0m" - BOLD = "\033[1m" - UNDERLINE = "\033[4m" + error_keys = { @@ -49,7 +41,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." + "picamera_import_error": "Picamera module could not be imported. Check physical connections to the camera as it may be damaged.", } if __name__ == "__main__": @@ -62,7 +54,7 @@ if __name__ == "__main__": error_sources.extend(check_settings.main()) error_sources.extend(check_picamera.main()) - #error_sources.extend(check_capture_reload.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 index e5f3210a..e31ed26d 100644 --- a/openflexure_microscope/rescue/check_picamera.py +++ b/openflexure_microscope/rescue/check_picamera.py @@ -1,5 +1,6 @@ import logging + def main(): error_sources = [] logging.info("Attempting to import picamera...") @@ -12,4 +13,4 @@ def main(): logging.error(e) error_sources.append("picamera_import_error") - return error_sources \ No newline at end of file + return error_sources diff --git a/openflexure_microscope/rescue/error_sources.py b/openflexure_microscope/rescue/error_sources.py new file mode 100644 index 00000000..9ed6f476 --- /dev/null +++ b/openflexure_microscope/rescue/error_sources.py @@ -0,0 +1,36 @@ +class bcolors: + HEADER = "\033[95m" + OKBLUE = "\033[94m" + OKGREEN = "\033[92m" + WARNING = "\033[93m" + FAIL = "\033[91m" + ENDC = "\033[0m" + BOLD = "\033[1m" + UNDERLINE = "\033[4m" + + +class Source: + def __init__(self, message): + self._message = message + + @property + def message(self): + return self._message + + +class WarningSource: + def __init__(self, message): + self.message = message + + @property + def message(self): + print(bcolors.WARNING + self._message + bcolors.ENDC) + + +class ErrorSource: + def __init__(self, message): + self.message = message + + @property + def message(self): + print(bcolors.FAIL + self._message + bcolors.ENDC) \ No newline at end of file