def build_ui(timeout: int) -> None: """Create a new UI build.""" try: # Project from hyperglass.configuration import CONFIG_PATH, params, frontend_params from hyperglass.util.frontend import build_frontend from hyperglass.compat._asyncio import aiorun except ImportError as e: error("Error importing UI builder: {e}", e=e) status("Starting new UI build with a {t} second timeout...", t=timeout) if params.developer_mode: dev_mode = "development" else: dev_mode = "production" try: build_success = aiorun( build_frontend( dev_mode=params.developer_mode, dev_url=f"http://localhost:{str(params.listen_port)}/", prod_url="/api/", params=frontend_params, force=True, app_path=CONFIG_PATH, )) if build_success: success("Completed UI build in {m} mode", m=dev_mode) except Exception as e: error("Error building UI: {e}", e=e) return True
def migrate_config(config_dir): """Copy example config files and remove .example extensions.""" status("Migrating example config files...") import shutil examples = Path(PROJECT_ROOT / "examples").glob("*.yaml.example") if not isinstance(config_dir, Path): config_dir = Path(config_dir) if not config_dir.exists(): error("'{d}' does not exist", d=str(config_dir)) migrated = 0 for file in examples: target_file = config_dir / file.with_suffix("").name try: if target_file.exists(): info("{f} already exists", f=str(target_file)) else: shutil.copyfile(file, target_file) migrated += 1 info("Migrated {f}", f=str(target_file)) except Exception as e: error("Failed to migrate '{f}': {e}", f=str(target_file), e=e) if migrated == 0: info("Migrated {n} example config files", n=migrated) elif migrated > 0: success("Successfully migrated {n} example config files", n=migrated)
def migrate_systemd(source, destination): """Copy example systemd service file to /etc/systemd/system/.""" import os import shutil basefile, extension = os.path.splitext(source) newfile = os.path.join(destination, basefile) try: status("Migrating example systemd service...") if os.path.exists(newfile): info("'{f}' already exists", f=str(newfile)) else: shutil.copyfile(source, newfile) except Exception as e: error("Error migrating example systemd service: {e}", e=e) success("Successfully migrated systemd service to: {f}", f=str(newfile))
def build_ui(): """Create a new UI build. Raises: ClickException: Raised on any errors. """ try: from hyperglass.compat._asyncio import aiorun from hyperglass.util import build_frontend from hyperglass.configuration import params, frontend_params, CONFIG_PATH except ImportError as e: error("Error importing UI builder: {e}", e=e) status("Starting new UI build...") if params.developer_mode: dev_mode = "development" else: dev_mode = "production" try: build_success = aiorun( build_frontend( dev_mode=params.developer_mode, dev_url=f"http://localhost:{str(params.listen_port)}/", prod_url="/api/", params=frontend_params, force=True, app_path=CONFIG_PATH, )) if build_success: success("Completed UI build in {m} mode", m=dev_mode) except Exception as e: error("Error building UI: {e}", e=e) return True