|
15 | 15 | from matlab_proxy.util.mwi.exceptions import ( |
16 | 16 | EmbeddedConnectorError, |
17 | 17 | EntitlementError, |
18 | | - InternalError, |
| 18 | + FatalError, |
19 | 19 | LicensingError, |
20 | 20 | MatlabError, |
21 | | - MatlabInstallError, |
22 | 21 | OnlineLicensingError, |
23 | 22 | XvfbError, |
24 | 23 | log_error, |
@@ -70,11 +69,12 @@ def __init__(self, settings): |
70 | 69 | self.logs = { |
71 | 70 | "matlab": deque(maxlen=200), |
72 | 71 | } |
73 | | - self.error = None |
74 | | - # Start in an error state if MATLAB is not present |
75 | | - if not self.is_matlab_present(): |
76 | | - self.error = MatlabInstallError("'matlab' executable not found in PATH") |
77 | | - logger.error("'matlab' executable not found in PATH") |
| 72 | + |
| 73 | + # Initialize with the error state from the initialization of settings |
| 74 | + self.error = settings["error"] |
| 75 | + |
| 76 | + if self.error is not None: |
| 77 | + self.logs["matlab"].clear() |
78 | 78 | return |
79 | 79 |
|
80 | 80 | # Keep track of when the Embedded connector starts. |
@@ -153,8 +153,8 @@ async def init_licensing(self): |
153 | 153 | self.__delete_cached_licensing_file() |
154 | 154 |
|
155 | 155 | # NLM Connection String set in environment |
156 | | - elif self.settings["nlm_conn_str"] is not None: |
157 | | - nlm_licensing_str = self.settings["nlm_conn_str"] |
| 156 | + elif self.settings.get("nlm_conn_str", None) is not None: |
| 157 | + nlm_licensing_str = self.settings.get("nlm_conn_str") |
158 | 158 | logger.debug(f"Found NLM:[{nlm_licensing_str}] set in environment") |
159 | 159 | logger.debug(f"Using NLM string to connect ... ") |
160 | 160 | self.licensing = { |
@@ -395,26 +395,17 @@ def is_licensed(self): |
395 | 395 | return True |
396 | 396 | return False |
397 | 397 |
|
398 | | - def is_matlab_present(self): |
399 | | - """Is MATLAB install accessible? |
400 | | -
|
401 | | - Returns: |
402 | | - Boolean: True if MATLAB is present in the system. False otherwise. |
403 | | - """ |
404 | | - |
405 | | - return self.settings["matlab_path"] is not None |
406 | | - |
407 | 398 | async def update_entitlements(self): |
408 | 399 | """Speaks to MW and updates MHLM entitlements |
409 | 400 |
|
410 | 401 | Raises: |
411 | | - InternalError: When licensing is None or when licensing type is not MHLM. |
| 402 | + FatalError: When licensing is None or when licensing type is not MHLM. |
412 | 403 |
|
413 | 404 | Returns: |
414 | 405 | Boolean: True if update was successful |
415 | 406 | """ |
416 | 407 | if self.licensing is None or self.licensing["type"] != "mhlm": |
417 | | - raise InternalError( |
| 408 | + raise FatalError( |
418 | 409 | "MHLM licensing must be configured to update entitlements!" |
419 | 410 | ) |
420 | 411 |
|
@@ -722,26 +713,8 @@ async def start_matlab(self, restart_matlab=False): |
722 | 713 |
|
723 | 714 | Args: |
724 | 715 | restart_matlab (bool, optional): Whether to restart MATLAB. Defaults to False. |
725 | | -
|
726 | | - Raises: |
727 | | - Exception: When MATLAB is already running and restart is False. |
728 | | - Exception: When MATLAB is not licensed. |
729 | 716 | """ |
730 | 717 |
|
731 | | - # FIXME |
732 | | - if await self.get_matlab_state() != "down" and restart_matlab is False: |
733 | | - raise Exception("MATLAB already running/starting!") |
734 | | - |
735 | | - # FIXME |
736 | | - if not self.is_licensed(): |
737 | | - raise Exception("MATLAB is not licensed!") |
738 | | - |
739 | | - if not self.is_matlab_present(): |
740 | | - self.error = MatlabInstallError("'matlab' executable not found in PATH") |
741 | | - logger.error("'matlab' executable not found in PATH") |
742 | | - self.logs["matlab"].clear() |
743 | | - return |
744 | | - |
745 | 718 | # Ensure that previous processes are stopped |
746 | 719 | await self.stop_matlab() |
747 | 720 |
|
|
0 commit comments