2020-01-21 01:08:28 -07:00
|
|
|
"""CLI utility functions."""
|
2021-01-12 00:14:23 -07:00
|
|
|
|
2020-02-03 02:35:11 -07:00
|
|
|
# Standard Library
|
2021-09-27 01:40:49 -07:00
|
|
|
import sys
|
2021-09-15 18:25:37 -07:00
|
|
|
import asyncio
|
2020-01-28 14:32:03 -07:00
|
|
|
|
2020-02-03 02:35:11 -07:00
|
|
|
# Third Party
|
2021-09-27 01:40:49 -07:00
|
|
|
import typer
|
2020-01-21 01:08:28 -07:00
|
|
|
|
2021-09-27 01:40:49 -07:00
|
|
|
# Local
|
|
|
|
from .echo import echo
|
2020-01-21 01:08:28 -07:00
|
|
|
|
|
|
|
|
2021-01-28 23:04:02 -07:00
|
|
|
def build_ui(timeout: int) -> None:
|
|
|
|
"""Create a new UI build."""
|
2021-09-27 01:40:49 -07:00
|
|
|
# Project
|
|
|
|
from hyperglass.state import use_state
|
|
|
|
from hyperglass.util.frontend import build_frontend
|
2020-01-21 17:28:32 -07:00
|
|
|
|
2021-09-15 18:25:37 -07:00
|
|
|
state = use_state()
|
|
|
|
|
2021-09-27 01:40:49 -07:00
|
|
|
dev_mode = "production"
|
|
|
|
if state.settings.dev_mode:
|
2020-01-21 17:28:32 -07:00
|
|
|
dev_mode = "development"
|
|
|
|
|
|
|
|
try:
|
2021-09-15 18:25:37 -07:00
|
|
|
build_success = asyncio.run(
|
2020-01-21 17:28:32 -07:00
|
|
|
build_frontend(
|
2021-09-27 01:40:49 -07:00
|
|
|
app_path=state.settings.app_path,
|
2021-09-15 18:25:37 -07:00
|
|
|
dev_mode=state.settings.dev_mode,
|
|
|
|
dev_url=f"http://localhost:{state.settings.port!s}/",
|
2020-01-21 17:28:32 -07:00
|
|
|
force=True,
|
2021-09-27 01:40:49 -07:00
|
|
|
params=state.ui_params,
|
|
|
|
prod_url="/api/",
|
|
|
|
timeout=timeout,
|
2020-01-21 17:28:32 -07:00
|
|
|
)
|
|
|
|
)
|
2020-02-14 16:27:08 -07:00
|
|
|
if build_success:
|
2021-09-27 01:40:49 -07:00
|
|
|
echo.success("Completed UI build in {} mode", dev_mode)
|
2020-02-14 16:27:08 -07:00
|
|
|
|
2020-01-21 17:28:32 -07:00
|
|
|
except Exception as e:
|
2021-09-27 01:40:49 -07:00
|
|
|
if not sys.stdout.isatty():
|
|
|
|
echo._console.print_exception(show_locals=True)
|
|
|
|
raise typer.Exit(1)
|
2020-07-19 14:42:54 -07:00
|
|
|
|
2021-09-27 01:40:49 -07:00
|
|
|
echo.error("Error building UI: {!s}", e)
|
|
|
|
raise typer.Exit(1)
|