1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

52 lines
1.3 KiB
Python
Raw Normal View History

2020-01-21 01:08:28 -07:00
"""CLI utility functions."""
2020-02-03 02:35:11 -07:00
# Standard Library
import sys
2021-09-15 18:25:37 -07:00
import asyncio
2020-02-03 02:35:11 -07:00
# Third Party
import typer
2020-01-21 01:08:28 -07:00
# Local
from .echo import echo
2020-01-21 01:08:28 -07:00
def build_ui(timeout: int) -> None:
"""Create a new UI build."""
# Project
from hyperglass.state import use_state
from hyperglass.configuration import init_user_config
from hyperglass.util.frontend import build_frontend
2020-01-21 17:28:32 -07:00
# Populate configuration to Redis prior to accessing it.
init_user_config()
2021-09-15 18:25:37 -07:00
state = use_state()
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(
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,
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:
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:
if not sys.stdout.isatty():
echo._console.print_exception(show_locals=True)
raise typer.Exit(1)
echo.error("Error building UI: {!s}", e)
raise typer.Exit(1)