From fab5cdb35ffcc16cb0b21ed900aa2170e31d0a24 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 19 Jan 2023 01:58:06 +0000 Subject: [PATCH 1/5] Print distro in doctor output --- lib/python/qmk/cli/doctor/check.py | 16 ++++++++++++++++ lib/python/qmk/cli/doctor/linux.py | 22 +++++++++++++++------- lib/python/qmk/cli/doctor/windows.py | 6 +++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 426876e98a82..689d4f5b6d57 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -158,3 +158,19 @@ 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 = line.split('=', 1) + ret[key.strip()] = value.strip() + except PermissionError: + pass + + return ret diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py index 95bafe8c6415..048bb210be50 100644 --- a/lib/python/qmk/cli/doctor/linux.py +++ b/lib/python/qmk/cli/doctor/linux.py @@ -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): @@ -130,17 +134,21 @@ 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}.") + release_id = release_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)) + + # 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 diff --git a/lib/python/qmk/cli/doctor/windows.py b/lib/python/qmk/cli/doctor/windows.py index 381ab36fde96..6831b77b97be 100644 --- a/lib/python/qmk/cli/doctor/windows.py +++ b/lib/python/qmk/cli/doctor/windows.py @@ -2,7 +2,7 @@ from milc import cli -from .check import CheckStatus +from .check import CheckStatus, release_info def os_test_windows(): @@ -11,4 +11,8 @@ 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]) + qmk_distro_version = release_info('/etc/qmk-release').get('VERSION', None) + if qmk_distro_version: + cli.log.info('QMK MSYS version: %s', qmk_distro_version) + return CheckStatus.OK From 3c9eba0b9f719339bd2d95bfb9fc73cda46490c1 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 19 Jan 2023 02:13:15 +0000 Subject: [PATCH 2/5] Use PRETTY_NAME? --- lib/python/qmk/cli/doctor/check.py | 6 ++++-- lib/python/qmk/cli/doctor/linux.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 689d4f5b6d57..4b0235e39b65 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -168,8 +168,10 @@ def release_info(file='/etc/os-release'): with open(file) as f: for line in f: if '=' in line: - key, value = line.split('=', 1) - ret[key.strip()] = value.strip() + key, value = map(str.strip, line.split('=', 1)) + if value.startswith('"') and value.endswith('"'): + value=value[1:-1] + ret[key] = value except PermissionError: pass diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py index 048bb210be50..faf85d84edc1 100644 --- a/lib/python/qmk/cli/doctor/linux.py +++ b/lib/python/qmk/cli/doctor/linux.py @@ -134,7 +134,8 @@ def check_modem_manager(): def os_test_linux(): """Run the Linux specific tests. """ - release_id = release_info().get('ID', 'Unknown') + 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)) From 43c672f0f18450c5eadf7d7d64cda223e108f2a3 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 19 Jan 2023 02:48:55 +0000 Subject: [PATCH 3/5] Fix windows --- lib/python/qmk/cli/doctor/check.py | 2 +- lib/python/qmk/cli/doctor/windows.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 4b0235e39b65..81fec7fc004f 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -172,7 +172,7 @@ def release_info(file='/etc/os-release'): if value.startswith('"') and value.endswith('"'): value=value[1:-1] ret[key] = value - except PermissionError: + except (PermissionError, FileNotFoundError): pass return ret diff --git a/lib/python/qmk/cli/doctor/windows.py b/lib/python/qmk/cli/doctor/windows.py index 6831b77b97be..26bb65374b84 100644 --- a/lib/python/qmk/cli/doctor/windows.py +++ b/lib/python/qmk/cli/doctor/windows.py @@ -11,7 +11,9 @@ 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]) - qmk_distro_version = release_info('/etc/qmk-release').get('VERSION', None) + # 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) From 9e84d1716eacdc179134eedcf5c9b308e193a2a3 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 19 Jan 2023 02:57:21 +0000 Subject: [PATCH 4/5] lint --- lib/python/qmk/cli/doctor/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 81fec7fc004f..cd69cdd11c8d 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -170,7 +170,7 @@ def release_info(file='/etc/os-release'): if '=' in line: key, value = map(str.strip, line.split('=', 1)) if value.startswith('"') and value.endswith('"'): - value=value[1:-1] + value = value[1:-1] ret[key] = value except (PermissionError, FileNotFoundError): pass From b54a46d5c659320aeff9da48488a158dc96936ee Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 19 Jan 2023 03:48:20 +0000 Subject: [PATCH 5/5] Review fixes --- lib/python/qmk/cli/doctor/linux.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py index faf85d84edc1..f0850d4e6488 100644 --- a/lib/python/qmk/cli/doctor/linux.py +++ b/lib/python/qmk/cli/doctor/linux.py @@ -136,9 +136,9 @@ def os_test_linux(): """ info = release_info() release_id = info.get('PRETTY_NAME', info.get('ID', 'Unknown')) - plat = 'Linux (WSL)' if _is_wsl() else 'Linux' + plat = 'WSL, ' if _is_wsl() else '' - cli.log.info("Detected {fg_cyan}%s{fg_reset} - {fg_green}%s{fg_reset}." % (plat, release_id)) + cli.log.info(f"Detected {{fg_cyan}}Linux ({plat}{release_id}){{fg_reset}}.") # Don't bother with udev on WSL, for now if _is_wsl():