Skip to content

Commit

Permalink
Update to version 0.2.3 and pretty print MATLAB access URL
Browse files Browse the repository at this point in the history
  • Loading branch information
diningPhilosopher64 authored and prabhakk-mw committed Feb 10, 2022
1 parent 8d2bccd commit 58d1910
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
14 changes: 7 additions & 7 deletions matlab_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,20 @@ def main():
f' with base_url: {app["settings"]["base_url"]} and app_port:{app["settings"]["app_port"]}.'
)

prefix = (
"MATLAB Proxy "
if os.environ.get(mwi_env.get_env_name_mhlm_context()) is None
else f'MATLAB Integration for {app["state"].settings["env_config"]["extension_name_short_description"]}'
)

ssl_context = app["settings"]["ssl_context"]
if ssl_context != None:
access_protocol = "https"
else:
access_protocol = "http"

logger.info(
f'\n================================\nThe {prefix} can be accessed on {access_protocol}://localhost:{app["settings"]["app_port"]}{app["settings"]["base_url"]}/index.html\n================================'
util.prettify(
boundary_filler="=",
text_arr=[
f"MATLAB can be accessed at:",
f'{access_protocol}://localhost:{app["settings"]["app_port"]}{app["settings"]["base_url"]}/index.html',
],
)
)

loop.run_forever()
Expand Down
33 changes: 33 additions & 0 deletions matlab_proxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import sys
import argparse
import os
import matlab_proxy
from aiohttp import web
from matlab_proxy import mwi_environment_variables as mwi_env
Expand Down Expand Up @@ -110,3 +111,35 @@ def add_signal_handlers(loop):
loop.add_signal_handler(signal, lambda: loop.stop())

return loop


def prettify(boundary_filler=" ", text_arr=[]):
"""Prettify array of strings with borders for stdout
Args:
boundary_filler (str, optional): Upper and lower border filler for text. Defaults to " ".
text_arr (list, optional):The text array to prettify. Each element will be added to a newline. Defaults to [].
Returns:
[str]: Prettified String
"""

size = os.get_terminal_size()
cols, _ = size.columns, size.lines

if any(len(text) > cols for text in text_arr):
result = ""
for text in text_arr:
result += text + "\n"
return result

upper = "\n" + "".ljust(cols, boundary_filler) + "\n" if len(text_arr) > 0 else ""
lower = "".ljust(cols, boundary_filler) if len(text_arr) > 0 else ""

content = ""
for text in text_arr:
content += text.center(cols) + "\n"

result = upper + content + lower

return result
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(self):

setuptools.setup(
name="matlab-proxy",
version="0.2.2",
version="0.2.3",
url=config["doc_url"],
author="The MathWorks, Inc.",
author_email="[email protected]",
Expand Down

0 comments on commit 58d1910

Please sign in to comment.