diff options
| author | Erovia <erovia@users.noreply.github.com> | 2019-10-24 18:50:35 +0200 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2020-01-11 12:18:30 -0800 |
| commit | c6f47b5bd76eaa1b64cd4bc97dc0f59ed4d99eb7 (patch) | |
| tree | 481ddd9f6f18fe54ec6bfea35b64c1f8d7903830 /lib | |
| parent | 70309bef3d47916f1b988aacc2fac598bd1f9d22 (diff) | |
| download | qmk_firmware-c6f47b5bd76eaa1b64cd4bc97dc0f59ed4d99eb7.tar.gz qmk_firmware-c6f47b5bd76eaa1b64cd4bc97dc0f59ed4d99eb7.zip | |
CLI: Rework ModemManager check and add udev check
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/python/qmk/cli/doctor.py | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 2421e520e..cbe44c9ae 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py | |||
| @@ -5,6 +5,7 @@ Check up for QMK environment. | |||
| 5 | import platform | 5 | import platform |
| 6 | import shutil | 6 | import shutil |
| 7 | import subprocess | 7 | import subprocess |
| 8 | import glob | ||
| 8 | 9 | ||
| 9 | from milc import cli | 10 | from milc import cli |
| 10 | 11 | ||
| @@ -46,23 +47,43 @@ def doctor(cli): | |||
| 46 | 47 | ||
| 47 | elif OS == "Linux": | 48 | elif OS == "Linux": |
| 48 | cli.log.info("Detected {fg_cyan}Linux.") | 49 | cli.log.info("Detected {fg_cyan}Linux.") |
| 49 | if shutil.which('systemctl'): | 50 | # Checking for udev rules |
| 50 | mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, universal_newlines=True) | 51 | udev_dir = "/etc/udev/rules.d/" |
| 51 | if mm_check.returncode == 0: | 52 | # These are the recommended udev rules |
| 52 | mm = False | 53 | desired_rules = {"dfu": {'SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2ff4", MODE:="0666"', |
| 53 | for line in mm_check.stdout.split('\n'): | 54 | 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2ffb", MODE:="0666"', |
| 54 | if 'ModemManager' in line and 'enabled' in line: | 55 | 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2ff0", MODE:="0666"'}, |
| 55 | mm = True | 56 | "tmk": {'SUBSYSTEMS=="usb", ATTRS{idVendor}=="feed", MODE:="0666"'}, |
| 56 | 57 | "input-club": {'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", MODE:="0666"'}, | |
| 57 | if mm: | 58 | "stm32": {'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1eaf", ATTRS{idProduct}=="0003", MODE:="0666"', |
| 58 | cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.") | 59 | 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="df11", MODE:="0666"'}, |
| 59 | 60 | "catalina": {'ATTRS{idVendor}=="2a03", ENV{ID_MM_DEVICE_IGNORE}="1"', | |
| 60 | else: | 61 | 'ATTRS{idVendor}=="2341", ENV{ID_MM_DEVICE_IGNORE}="1"'}} |
| 61 | cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:') | 62 | if os.path.exists(udev_dir): |
| 62 | cli.log.error(mm_check.stderr) | 63 | udev_rules = [rule for rule in glob.iglob(os.path.join(udev_dir, "*.rules")) if os.path.isfile(rule)] |
| 63 | 64 | # Collect all rules from the config files | |
| 64 | else: | 65 | current_rules = set() |
| 65 | cli.log.warn("Can't find systemctl to check for ModemManager.") | 66 | for rule in udev_rules: |
| 67 | with open(rule, "r") as fd: | ||
| 68 | for line in fd.readlines(): | ||
| 69 | line = line.strip() | ||
| 70 | if not line.startswith("#") and len(line): | ||
| 71 | current_rules.add(line) | ||
| 72 | |||
| 73 | # Check if the desired rules are among the currently present rules | ||
| 74 | for bootloader, rules in desired_rules.items(): | ||
| 75 | if not rules.issubset(current_rules): | ||
| 76 | # If the rules for catalina are not present, check if ModemManager is running | ||
| 77 | if bootloader == "catalina": | ||
| 78 | if shutil.which("systemctl"): | ||
| 79 | mm_check = subprocess.run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10) | ||
| 80 | if mm_check.returncode == 0: | ||
| 81 | ok = False | ||
| 82 | cli.log.warn("{bg_yellow}Detected ModemManager without udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro-Micro.") | ||
| 83 | else: | ||
| 84 | cli.log.warn("Can't find systemctl to check for ModemManager.") | ||
| 85 | else: | ||
| 86 | cli.log.warn("{bg_yellow}Missing udev rules for '%s' boards. You'll need to use `sudo` in order to flash them.", bootloader) | ||
| 66 | 87 | ||
| 67 | else: | 88 | else: |
| 68 | cli.log.info("Assuming {fg_cyan}Windows.") | 89 | cli.log.info("Assuming {fg_cyan}Windows.") |
