diff --git a/hyperglass/cli/util.py b/hyperglass/cli/util.py index 981b84b..1a6759a 100644 --- a/hyperglass/cli/util.py +++ b/hyperglass/cli/util.py @@ -148,12 +148,12 @@ def write_to_file(file, data) -> bool: return True -def system_info() -> bool: +def system_info() -> None: """Create a markdown table of various system information.""" # Project from hyperglass.util.system_info import get_system_info - values = get_system_info() + data = get_system_info() def _code(val): return f"`{str(val)}`" @@ -161,39 +161,21 @@ def system_info() -> bool: def _bold(val): return f"**{str(val)}**" - def _suffix(val, suffix): - return f"{str(val)}{str(suffix)}" + md_table_lines = ("| Metric | Value |", "| :----- | :---- |") - columns = ( - ("hyperglass Version", _bold), - ("hyperglass Path", _code), - ("Python Version", _code), - ("Platform Info", _code), - ("CPU Info", None), - ("Logical Cores", _code), - ("Physical Cores", _code), - ("Processor Speed", "GHz"), - ("Total Memory", " GB"), - ("Memory Utilization", "%"), - ("Total Disk Space", " GB"), - ("Disk Utilization", "%"), - ) - md_table_lines = ("| Metric | Value |", "| ------ | ----- |") + for title, metric in data.items(): + value, mod = metric - for i, metric in enumerate(values): - title, mod = columns[i] - value = metric + title = _bold(title) - if isinstance(mod, str): - value = _suffix(value, mod) - elif callable(mod): - value = mod(value) + if mod == "code": + value = _code(value) - md_table_lines += (f"| **{title}** | {value} |",) + md_table_lines += (f"| {title} | {value} |",) md_table = "\n".join(md_table_lines) info("Please copy & paste this table in your bug report:\n") echo(md_table + "\n") - return True + return None diff --git a/hyperglass/main.py b/hyperglass/main.py index 7edf673..4741481 100644 --- a/hyperglass/main.py +++ b/hyperglass/main.py @@ -23,9 +23,9 @@ if sys.version_info < MIN_PYTHON_VERSION: raise RuntimeError(f"Python {pretty_version}+ is required.") # Ensure the NodeJS version meets the minimum requirements. -node_version = get_node_version() +node_major, _, __ = get_node_version() -if node_version != MIN_NODE_VERSION: +if node_major != MIN_NODE_VERSION: raise RuntimeError(f"NodeJS {MIN_NODE_VERSION}+ is required.") diff --git a/hyperglass/util/frontend.py b/hyperglass/util/frontend.py index 130bb6f..1d2480a 100644 --- a/hyperglass/util/frontend.py +++ b/hyperglass/util/frontend.py @@ -7,7 +7,7 @@ import math import shutil import asyncio import subprocess -from typing import Dict, Optional +from typing import Dict, Tuple, Optional from pathlib import Path # Project @@ -17,7 +17,7 @@ from hyperglass.log import log from .files import copyfiles, check_path -def get_node_version() -> int: +def get_node_version() -> Tuple[int, int, int]: """Get the system's NodeJS version.""" node_path = shutil.which("node") @@ -28,9 +28,7 @@ def get_node_version() -> int: # Node returns the version as 'v14.5.0', for example. Remove the v. version = raw_version.replace("v", "") # Parse the version parts. - major, minor, patch = version.split(".") - - return int(major) + return tuple((int(v) for v in version.split("."))) def get_ui_build_timeout() -> Optional[int]: diff --git a/hyperglass/util/system_info.py b/hyperglass/util/system_info.py index 82ded69..10994b6 100644 --- a/hyperglass/util/system_info.py +++ b/hyperglass/util/system_info.py @@ -3,6 +3,7 @@ # Standard Library import os import platform +from typing import Dict, Tuple, Union # Third Party import psutil as _psutil @@ -11,8 +12,13 @@ from cpuinfo import get_cpu_info as _get_cpu_info # Project from hyperglass.constants import __version__ +# Local +from .frontend import get_node_version -def _cpu(): +SystemData = Dict[str, Tuple[Union[str, int], str]] + + +def _cpu() -> SystemData: """Construct CPU Information.""" cpu_info = _get_cpu_info() brand = cpu_info.get("brand_raw", "") @@ -22,7 +28,7 @@ def _cpu(): return (brand, cores_logical, cores_raw, cpu_ghz) -def _memory(): +def _memory() -> SystemData: """Construct RAM Information.""" mem_info = _psutil.virtual_memory() total_gb = round(mem_info.total / 1e9, 2) @@ -30,7 +36,7 @@ def _memory(): return (total_gb, usage_percent) -def _disk(): +def _disk() -> SystemData: """Construct Disk Information.""" disk_info = _psutil.disk_usage("/") total_gb = round(disk_info.total / 1e9, 2) @@ -38,19 +44,25 @@ def _disk(): return (total_gb, usage_percent) -def get_system_info(): +def get_system_info() -> SystemData: """Get system info.""" - yield __version__ - yield os.environ["hyperglass_directory"] + cpu_info, cpu_logical, cpu_physical, cpu_speed = _cpu() + mem_total, mem_usage = _memory() + disk_total, disk_usage = _disk() - yield platform.python_version() - - yield platform.platform() - - for c in _cpu(): - yield c - for m in _memory(): - yield m - for d in _disk(): - yield d + return { + "hyperglass Version": (__version__, "text"), + "hyperglass Path": (os.environ["hyperglass_directory"], "code"), + "Python Version": (platform.python_version(), "code"), + "Node Version": (".".join(str(v) for v in get_node_version()), "code"), + "Platform Info": (platform.platform(), "code"), + "CPU Info": (cpu_info, "text"), + "Logical Cores": (cpu_logical, "code"), + "Physical Cores": (cpu_physical, "code"), + "Processor Speed": (f"{cpu_speed}GHz", "code"), + "Total Memory": (f"{mem_total} GB", "text"), + "Memory Utilization": (f"{mem_usage}%", "text"), + "Total Disk Space": (f"{disk_total} GB", "text"), + "Disk Utilization": (f"{disk_usage}%", "text"), + }