|
33 | 33 | MatlabInstallError, |
34 | 34 | OnlineLicensingError, |
35 | 35 | UIVisibleFatalError, |
36 | | - XvfbError, |
37 | 36 | WindowManagerError, |
| 37 | + XvfbError, |
38 | 38 | log_error, |
39 | 39 | ) |
40 | 40 |
|
41 | 41 | logger = mwi.logger.get() |
42 | 42 |
|
43 | 43 |
|
| 44 | +def _get_server_urls(server_url: str, mwi_auth_token_str: str) -> list[str]: |
| 45 | + """Returns list of server URLs including user supplied hostname, if any.""" |
| 46 | + # By default mwi_server_url usually points to 0.0.0.0 as the hostname, but this does not work well |
| 47 | + # on some browsers. Specifically on Safari (MacOS), hence the replace op with localhost. |
| 48 | + server_urls_with_auth_token = [ |
| 49 | + f'{server_url.replace("0.0.0.0", "localhost")}{mwi_auth_token_str}' |
| 50 | + ] |
| 51 | + if user_supplied_hostname := os.getenv(mwi_env.get_env_name_app_host(), "").strip(): |
| 52 | + server_urls_with_auth_token.append( |
| 53 | + f'{server_urls_with_auth_token[0].replace("localhost", user_supplied_hostname)}' |
| 54 | + ) |
| 55 | + |
| 56 | + return server_urls_with_auth_token |
| 57 | + |
| 58 | + |
44 | 59 | class AppState: |
45 | 60 | """A Class which represents the state of the App. |
46 | 61 | This class handles state of MATLAB, MATLAB Licensing and Xvfb. |
@@ -219,15 +234,15 @@ def __get_cached_config_file(self): |
219 | 234 | def __delete_cached_config_file(self): |
220 | 235 | """Deletes the cached config file""" |
221 | 236 | try: |
222 | | - logger.debug(f"Deleting any cached config files!") |
| 237 | + logger.debug("Deleting any cached config files!") |
223 | 238 | os.remove(self.__get_cached_config_file()) |
224 | 239 | except FileNotFoundError: |
225 | 240 | # The file being absent is acceptable. |
226 | 241 | pass |
227 | 242 |
|
228 | 243 | def __reset_and_delete_cached_config(self): |
229 | 244 | """Reset licensing variable of the class and removes the cached config file.""" |
230 | | - logger.debug(f"Resetting cached config information...") |
| 245 | + logger.debug("Resetting cached config information...") |
231 | 246 | self.licensing = None |
232 | 247 | self.__delete_cached_config_file() |
233 | 248 |
|
@@ -263,7 +278,7 @@ async def init_licensing(self): |
263 | 278 | f"{mwi_env.get_env_name_mwi_use_existing_license()} variable set in environment" |
264 | 279 | ) |
265 | 280 | logger.info( |
266 | | - f"!!! Starting MATLAB without providing any additional licensing information. This requires MATLAB to have been activated on the machine from which its being started !!!" |
| 281 | + "!!! Starting MATLAB without providing any additional licensing information. This requires MATLAB to have been activated on the machine from which its being started !!!" |
267 | 282 | ) |
268 | 283 |
|
269 | 284 | # Delete old config info from cache to ensure its wiped out first before persisting new info. |
@@ -342,7 +357,7 @@ async def init_licensing(self): |
342 | 357 | else: |
343 | 358 | # Somethings wrong, licensing is neither NLM or MHLM |
344 | 359 | self.__reset_and_delete_cached_config() |
345 | | - except Exception as e: |
| 360 | + except Exception: |
346 | 361 | self.__reset_and_delete_cached_config() |
347 | 362 |
|
348 | 363 | async def __update_matlab_state_based_on_connector_state(self): |
@@ -900,16 +915,11 @@ def create_server_info_file(self): |
900 | 915 | self.mwi_server_session_files["mwi_server_info_file"] = mwi_server_info_file |
901 | 916 | logger.debug(f"Server info stored into: {mwi_server_info_file}") |
902 | 917 |
|
903 | | - # By default mwi_server_url usually points to 0.0.0.0 as the hostname, but this does not work well |
904 | | - # on some browsers. Specifically on Safari (MacOS) |
905 | | - server_url = ( |
906 | | - self.settings["mwi_server_url"].replace("0.0.0.0", "localhost") |
907 | | - + mwi_auth_token_str |
908 | | - ) |
909 | | - |
910 | 918 | mwi.logger.log_startup_info( |
911 | 919 | title=f"matlab-proxy-app running on {self.settings['app_port']}", |
912 | | - matlab_url=server_url, |
| 920 | + matlab_urls=_get_server_urls( |
| 921 | + self.settings["mwi_server_url"], mwi_auth_token_str |
| 922 | + ), |
913 | 923 | ) |
914 | 924 | logger.info(f"MATLAB Root: {self.settings['matlab_path']}") |
915 | 925 |
|
@@ -1103,7 +1113,7 @@ async def __start_xvfb_process(self): |
1103 | 1113 |
|
1104 | 1114 | # FileNotFoundError: is thrown if Xvfb is not found on System Path. |
1105 | 1115 | # XvfbError: is thrown if something went wrong when starting Xvfb process. |
1106 | | - except (FileNotFoundError, XvfbError) as err: |
| 1116 | + except (FileNotFoundError, XvfbError): |
1107 | 1117 | self.error = XvfbError( |
1108 | 1118 | """Unable to start the Xvfb process. Ensure Xvfb is installed and is available on the System Path. See https://github.com/mathworks/matlab-proxy#requirements for information on Xvfb""" |
1109 | 1119 | ) |
@@ -1309,7 +1319,7 @@ async def start_matlab(self, restart_matlab=False): |
1309 | 1319 | # to MATLAB state by other functions/tasks until the lock is released, ensuring consistency. It's released early only in case of exceptions. |
1310 | 1320 | await self.matlab_state_updater_lock.acquire() |
1311 | 1321 | self.set_matlab_state("starting") |
1312 | | - logger.info(f"Starting MATLAB...") |
| 1322 | + logger.info("Starting MATLAB...") |
1313 | 1323 |
|
1314 | 1324 | # Clear MATLAB errors and logging |
1315 | 1325 | self.error = None |
|
0 commit comments