summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/doctor
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/doctor')
-rw-r--r--lib/python/qmk/cli/doctor/check.py93
-rw-r--r--lib/python/qmk/cli/doctor/linux.py34
-rwxr-xr-xlib/python/qmk/cli/doctor/main.py8
-rw-r--r--lib/python/qmk/cli/doctor/windows.py8
4 files changed, 95 insertions, 48 deletions
diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py
index 8a0422ba72..cd69cdd11c 100644
--- a/lib/python/qmk/cli/doctor/check.py
+++ b/lib/python/qmk/cli/doctor/check.py
@@ -3,7 +3,7 @@
from enum import Enum
import re
import shutil
-from subprocess import DEVNULL
+from subprocess import DEVNULL, TimeoutExpired
from milc import cli
from qmk import submodules
@@ -41,9 +41,8 @@ def _parse_gcc_version(version):
def _check_arm_gcc_version():
"""Returns True if the arm-none-eabi-gcc version is not known to cause problems.
"""
- if 'output' in ESSENTIAL_BINARIES['arm-none-eabi-gcc']:
- version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
- cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
+ version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
+ cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
return CheckStatus.OK # Right now all known arm versions are ok
@@ -51,44 +50,37 @@ def _check_arm_gcc_version():
def _check_avr_gcc_version():
"""Returns True if the avr-gcc version is not known to cause problems.
"""
- rc = CheckStatus.ERROR
- if 'output' in ESSENTIAL_BINARIES['avr-gcc']:
- version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
+ version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
+ cli.log.info('Found avr-gcc version %s', version_number)
- cli.log.info('Found avr-gcc version %s', version_number)
- rc = CheckStatus.OK
+ parsed_version = _parse_gcc_version(version_number)
+ if parsed_version['major'] > 8:
+ cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
+ return CheckStatus.WARNING
- parsed_version = _parse_gcc_version(version_number)
- if parsed_version['major'] > 8:
- cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
- rc = CheckStatus.WARNING
-
- return rc
+ return CheckStatus.OK
def _check_avrdude_version():
- if 'output' in ESSENTIAL_BINARIES['avrdude']:
- last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2]
- version_number = last_line.split()[2][:-1]
- cli.log.info('Found avrdude version %s', version_number)
+ last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2]
+ version_number = last_line.split()[2][:-1]
+ cli.log.info('Found avrdude version %s', version_number)
return CheckStatus.OK
def _check_dfu_util_version():
- if 'output' in ESSENTIAL_BINARIES['dfu-util']:
- first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0]
- version_number = first_line.split()[1]
- cli.log.info('Found dfu-util version %s', version_number)
+ first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0]
+ version_number = first_line.split()[1]
+ cli.log.info('Found dfu-util version %s', version_number)
return CheckStatus.OK
def _check_dfu_programmer_version():
- if 'output' in ESSENTIAL_BINARIES['dfu-programmer']:
- first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0]
- version_number = first_line.split()[1]
- cli.log.info('Found dfu-programmer version %s', version_number)
+ first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0]
+ version_number = first_line.split()[1]
+ cli.log.info('Found dfu-programmer version %s', version_number)
return CheckStatus.OK
@@ -96,11 +88,16 @@ def _check_dfu_programmer_version():
def check_binaries():
"""Iterates through ESSENTIAL_BINARIES and tests them.
"""
- ok = True
+ ok = CheckStatus.OK
for binary in sorted(ESSENTIAL_BINARIES):
- if not is_executable(binary):
- ok = False
+ try:
+ if not is_executable(binary):
+ ok = CheckStatus.ERROR
+ except TimeoutExpired:
+ cli.log.debug('Timeout checking %s', binary)
+ if ok != CheckStatus.ERROR:
+ ok = CheckStatus.WARNING
return ok
@@ -108,8 +105,22 @@ def check_binaries():
def check_binary_versions():
"""Check the versions of ESSENTIAL_BINARIES
"""
+ checks = {
+ 'arm-none-eabi-gcc': _check_arm_gcc_version,
+ 'avr-gcc': _check_avr_gcc_version,
+ 'avrdude': _check_avrdude_version,
+ 'dfu-util': _check_dfu_util_version,
+ 'dfu-programmer': _check_dfu_programmer_version,
+ }
+
versions = []
- for check in (_check_arm_gcc_version, _check_avr_gcc_version, _check_avrdude_version, _check_dfu_util_version, _check_dfu_programmer_version):
+ for binary in sorted(ESSENTIAL_BINARIES):
+ if 'output' not in ESSENTIAL_BINARIES[binary]:
+ cli.log.warning('Unknown version for %s', binary)
+ versions.append(CheckStatus.WARNING)
+ continue
+
+ check = checks[binary]
versions.append(check())
return versions
@@ -119,10 +130,8 @@ def check_submodules():
"""
for submodule in submodules.status().values():
if submodule['status'] is None:
- cli.log.error('Submodule %s has not yet been cloned!', submodule['name'])
return CheckStatus.ERROR
elif not submodule['status']:
- cli.log.warning('Submodule %s is not up to date!', submodule['name'])
return CheckStatus.WARNING
return CheckStatus.OK
@@ -149,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
diff --git a/lib/python/qmk/cli/doctor/linux.py b/lib/python/qmk/cli/doctor/linux.py
index a803305c0d..f0850d4e64 100644
--- a/lib/python/qmk/cli/doctor/linux.py
+++ b/lib/python/qmk/cli/doctor/linux.py
@@ -7,7 +7,11 @@ from pathlib import Path
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):
@@ -78,10 +82,13 @@ def check_udev_rules():
# Collect all rules from the config files
for rule_file in udev_rules:
- for line in rule_file.read_text(encoding='utf-8').split('\n'):
- line = line.strip()
- if not line.startswith("#") and len(line):
- current_rules.add(line)
+ try:
+ for line in rule_file.read_text(encoding='utf-8').split('\n'):
+ line = line.strip()
+ if not line.startswith("#") and len(line):
+ current_rules.add(line)
+ except PermissionError:
+ cli.log.debug("Failed to read: %s", rule_file)
# Check if the desired rules are among the currently present rules
for bootloader, rules in desired_rules.items():
@@ -127,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 = 'WSL, ' if _is_wsl() else ''
+ 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():
# 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/main.py b/lib/python/qmk/cli/doctor/main.py
index 1600ab8dd4..6a6feb87d1 100755
--- a/lib/python/qmk/cli/doctor/main.py
+++ b/lib/python/qmk/cli/doctor/main.py
@@ -119,13 +119,15 @@ def doctor(cli):
# Make sure the basic CLI tools we need are available and can be executed.
bin_ok = check_binaries()
- if not bin_ok:
+ if bin_ok == CheckStatus.ERROR:
if yesno('Would you like to install dependencies?', default=True):
cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False)
bin_ok = check_binaries()
- if bin_ok:
+ if bin_ok == CheckStatus.OK:
cli.log.info('All dependencies are installed.')
+ elif bin_ok == CheckStatus.WARNING:
+ cli.log.warning('Issues encountered while checking dependencies.')
else:
status = CheckStatus.ERROR
@@ -142,7 +144,7 @@ def doctor(cli):
if sub_ok == CheckStatus.OK:
cli.log.info('Submodules are up to date.')
else:
- if yesno('Would you like to clone the submodules?', default=True):
+ if git_check_repo() and yesno('Would you like to clone the submodules?', default=True):
submodules.update()
sub_ok = check_submodules()
diff --git a/lib/python/qmk/cli/doctor/windows.py b/lib/python/qmk/cli/doctor/windows.py
index 381ab36fde..26bb65374b 100644
--- a/lib/python/qmk/cli/doctor/windows.py
+++ b/lib/python/qmk/cli/doctor/windows.py
@@ -2,7 +2,7 @@ import platform
from milc import cli
-from .check import CheckStatus
+from .check import CheckStatus, release_info
def os_test_windows():
@@ -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