Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print distro in doctor output #19633

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/python/qmk/cli/doctor/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,21 @@ def is_executable(command):

cli.log.error("{fg_red}Can't run `%s %s`", command, version_arg)
return False


def release_info(file='/etc/os-release'):
"""Parse release info to dict
"""
ret = {}
try:
with open(file) as f:
for line in f:
if '=' in line:
key, value = map(str.strip, line.split('=', 1))
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
ret[key] = value
except (PermissionError, FileNotFoundError):
pass

return ret
23 changes: 16 additions & 7 deletions lib/python/qmk/cli/doctor/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from milc import cli

from qmk.constants import QMK_FIRMWARE, BOOTLOADER_VIDS_PIDS
from .check import CheckStatus
from .check import CheckStatus, release_info


def _is_wsl():
return 'microsoft' in platform.uname().release.lower()


def _udev_rule(vid, pid=None, *args):
Expand Down Expand Up @@ -130,17 +134,22 @@ def check_modem_manager():
def os_test_linux():
"""Run the Linux specific tests.
"""
# Don't bother with udev on WSL, for now
if 'microsoft' in platform.uname().release.lower():
cli.log.info("Detected {fg_cyan}Linux (WSL){fg_reset}.")
info = release_info()
release_id = info.get('PRETTY_NAME', info.get('ID', 'Unknown'))
plat = 'Linux (WSL)' if _is_wsl() else 'Linux'

cli.log.info("Detected {fg_cyan}%s{fg_reset} - {fg_green}%s{fg_reset}." % (plat, release_id))
zvecr marked this conversation as resolved.
Show resolved Hide resolved

# Don't bother with udev on WSL, for now
if _is_wsl():
# https://github.com/microsoft/WSL/issues/4197
if QMK_FIRMWARE.as_posix().startswith("/mnt"):
cli.log.warning("I/O performance on /mnt may be extremely slow.")
return CheckStatus.WARNING

return CheckStatus.OK
else:
cli.log.info("Detected {fg_cyan}Linux{fg_reset}.")
rc = check_udev_rules()
if rc != CheckStatus.OK:
return rc

return check_udev_rules()
return CheckStatus.OK
8 changes: 7 additions & 1 deletion lib/python/qmk/cli/doctor/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from milc import cli

from .check import CheckStatus
from .check import CheckStatus, release_info


def os_test_windows():
Expand All @@ -11,4 +11,10 @@ def os_test_windows():
win32_ver = platform.win32_ver()
cli.log.info("Detected {fg_cyan}Windows %s (%s){fg_reset}.", win32_ver[0], win32_ver[1])

# MSYS really does not like "/" files - resolve manually
file = cli.run(['cygpath', '-m', '/etc/qmk-release']).stdout.strip()
qmk_distro_version = release_info(file).get('VERSION', None)
if qmk_distro_version:
cli.log.info('QMK MSYS version: %s', qmk_distro_version)

return CheckStatus.OK