Skip to content

Commit

Permalink
Implement more system info
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Aug 22, 2020
1 parent fe01e46 commit 15df764
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
23 changes: 16 additions & 7 deletions src/ovshell_core/aboutapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def create(self) -> urwid.Widget:
]
)

versions_header = urwid.Text([("highlight", "Version information")])
versions_header = urwid.Text([("highlight", "System information")])

self.versions = urwid.Pile([])

Expand All @@ -84,10 +84,12 @@ def activate(self) -> None:

def _populate_versions(self) -> None:
ver_defs = [
("Openvario", self.sys_info.get_openvario_version()),
("XCSoar", self.sys_info.get_installed_package_version("xcsoar")),
("Sensor daemon", self.sys_info.get_installed_package_version("sensord")),
("Vario daemon", self.sys_info.get_installed_package_version("variod")),
("Openvario image", self.sys_info.get_openvario_version()),
("XCSoar", self._get_any_version(["xcsoar", "xcsoar-testing"])),
("Sensor daemon", self._get_any_version(["sensord", "sensord-testing"]),),
("Vario daemon", self._get_any_version(["variod", "veriod-testing"]),),
("Linux kernel", self.sys_info.get_kernel_version()),
("Hostname", self.sys_info.get_hostname()),
]
contents = [(self._make_version_wdg(t, f), ("pack", None)) for t, f in ver_defs]
self.versions.contents = contents
Expand All @@ -96,17 +98,24 @@ def _make_version_wdg(
self, title: str, fetcher: Coroutine[None, None, Optional[str]]
) -> urwid.Widget:
version_wdg = urwid.Text(("progress", "..."))
self.shell.screen.spawn_task(self, self._fetch_version(version_wdg, fetcher))
self.shell.screen.spawn_task(self, self._update_version(version_wdg, fetcher))
return urwid.Columns(
[("weight", 1, urwid.Text(title)), ("weight", 3, version_wdg)],
dividechars=1,
)

async def _fetch_version(
async def _update_version(
self, wdg: urwid.Text, fetcher: Coroutine[None, None, Optional[str]]
) -> None:
ver = await fetcher
if ver is not None:
wdg.set_text(("success message", ver))
else:
wdg.set_text("N/A")

async def _get_any_version(self, pkgs: List[str]) -> Optional[str]:
for pkgname in pkgs:
ver = await self.sys_info.get_installed_package_version(pkgname)
if ver is not None:
return ver
return None
10 changes: 6 additions & 4 deletions src/ovshell_core/sysinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import abstractmethod
import asyncio
import os
import platform
import re
from typing import Dict, List, Optional, Tuple, cast

Expand All @@ -21,7 +22,7 @@ async def get_kernel_version(self) -> Optional[str]:
"""Return kernel version"""

@abstractmethod
async def fetch_hostname(self) -> Optional[str]:
async def get_hostname(self) -> Optional[str]:
"""Return hostname"""


Expand Down Expand Up @@ -50,10 +51,11 @@ async def get_installed_package_version(self, package_name: str) -> Optional[str
return self._installed_pkgs.get(package_name)

async def get_kernel_version(self) -> Optional[str]:
return None
uname = os.uname()
return f"{uname.sysname} {uname.release}"

async def fetch_hostname(self) -> Optional[str]:
return None
async def get_hostname(self) -> Optional[str]:
return os.uname().nodename

async def _read_installed_packages(self) -> Dict[str, str]:
proc = await self.os.run("//usr/bin/opkg", ["list-installed"])
Expand Down
16 changes: 12 additions & 4 deletions tests/ovshell_core_tests/test_aboutapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Tuple
from typing import Dict, List, Optional, Tuple
import asyncio
import pytest

Expand All @@ -10,16 +10,21 @@


class SystemInfoStub(SystemInfo):
pkg_versions: Dict[str, str]

def __init__(self) -> None:
self.pkg_versions = {}

async def get_openvario_version(self) -> Optional[str]:
return "00000 (stub)"

async def get_installed_package_version(self, package_name: str) -> Optional[str]:
return None
return self.pkg_versions.get(package_name)

async def get_kernel_version(self) -> Optional[str]:
return "5.7.0-stub"

async def fetch_hostname(self) -> Optional[str]:
async def get_hostname(self) -> Optional[str]:
return "openvario-stub"


Expand All @@ -40,8 +45,10 @@ class TestAboutActivity:
@pytest.mark.asyncio
async def test_wizard_diplay(self, ovshell: testing.OpenVarioShellStub) -> None:
# GIVEN
sys_info_stub = SystemInfoStub()
sys_info_stub.pkg_versions = {"xcsoar-testing": "7.0.0-preview15"}
act = aboutapp.AboutActivity(ovshell)
act.sys_info = SystemInfoStub()
act.sys_info = sys_info_stub
w = act.create()
act.activate()

Expand All @@ -56,6 +63,7 @@ async def test_wizard_diplay(self, ovshell: testing.OpenVarioShellStub) -> None:
rendered = _render(w)
assert "..." not in rendered
assert "N/A" in rendered
assert "7.0.0-preview15" in rendered
assert "00000 (stub)" in rendered


Expand Down
20 changes: 20 additions & 0 deletions tests/ovshell_core_tests/test_sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,23 @@ async def test_get_installed_package_version_concurrent(
assert ovshell.get_stub_log() == [
"OS: Running //usr/bin/opkg list-installed",
]

@pytest.mark.asyncio
async def test_get_kernel_version(
self, ovshell: testing.OpenVarioShellStub
) -> None:
# GIVEN
sysinfo = SystemInfoImpl(ovshell.os)
# WHEN
ver = await sysinfo.get_kernel_version()
# THEN
assert ver is not None

@pytest.mark.asyncio
async def test_get_hostname(self, ovshell: testing.OpenVarioShellStub) -> None:
# GIVEN
sysinfo = SystemInfoImpl(ovshell.os)
# WHEN
ver = await sysinfo.get_hostname()
# THEN
assert ver is not None

0 comments on commit 15df764

Please sign in to comment.