diff options
| author | skullY <skullydazed@gmail.com> | 2019-08-22 09:38:10 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-09-07 07:58:41 -0700 |
| commit | 533d6d6a464d41d23a39cecfe42d95d2e400d335 (patch) | |
| tree | 2d74eb2f467ded0b34f295ef593bc8b9ce70fd98 | |
| parent | c7eede2249d22dd4fabed83043dcf4cc7408cf27 (diff) | |
| download | qmk_firmware-533d6d6a464d41d23a39cecfe42d95d2e400d335.tar.gz qmk_firmware-533d6d6a464d41d23a39cecfe42d95d2e400d335.zip | |
Make the modem manager check more pythonic
| -rwxr-xr-x | lib/python/qmk/cli/doctor.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index c5a144363..5a713b20f 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py | |||
| @@ -21,17 +21,17 @@ def main(cli): | |||
| 21 | * [ ] Compile a trivial program with each compiler | 21 | * [ ] Compile a trivial program with each compiler |
| 22 | * [ ] Check for udev entries on linux | 22 | * [ ] Check for udev entries on linux |
| 23 | """ | 23 | """ |
| 24 | cli.log.info('QMK Doctor is checking your environment.') | ||
| 24 | 25 | ||
| 26 | # Make sure the basic CLI tools we need are available and can be executed. | ||
| 25 | binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] | 27 | binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc'] |
| 26 | binaries += glob('bin/qmk-*') | 28 | binaries += glob('bin/qmk-*') |
| 27 | |||
| 28 | cli.log.info('QMK Doctor is checking your environment') | ||
| 29 | |||
| 30 | ok = True | 29 | ok = True |
| 30 | |||
| 31 | for binary in binaries: | 31 | for binary in binaries: |
| 32 | res = shutil.which(binary) | 32 | res = shutil.which(binary) |
| 33 | if res is None: | 33 | if res is None: |
| 34 | cli.log.error("{fg_red}QMK can't find %s in your path", binary) | 34 | cli.log.error("{fg_red}QMK can't find %s in your path.", binary) |
| 35 | ok = False | 35 | ok = False |
| 36 | else: | 36 | else: |
| 37 | try: | 37 | try: |
| @@ -40,20 +40,36 @@ def main(cli): | |||
| 40 | cli.log.error("{fg_red}Can't run `%s --version`", binary) | 40 | cli.log.error("{fg_red}Can't run `%s --version`", binary) |
| 41 | ok = False | 41 | ok = False |
| 42 | 42 | ||
| 43 | # Determine our OS and run platform specific tests | ||
| 43 | OS = platform.system() | 44 | OS = platform.system() |
| 45 | |||
| 44 | if OS == "Darwin": | 46 | if OS == "Darwin": |
| 45 | cli.log.info("Detected {fg_cyan}macOS") | 47 | cli.log.info("Detected {fg_cyan}macOS.") |
| 48 | |||
| 46 | elif OS == "Linux": | 49 | elif OS == "Linux": |
| 47 | cli.log.info("Detected {fg_cyan}linux") | 50 | cli.log.info("Detected {fg_cyan}Linux.") |
| 48 | if shutil.which('systemctl'): | 51 | if shutil.which('systemctl'): |
| 49 | test = 'systemctl list-unit-files | grep enabled | grep -i ModemManager' | 52 | mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10) |
| 50 | if os.system(test) == 0: | 53 | if mm_check.returncode == 0: |
| 51 | cli.log.warn("{bg_yellow}Detected modem manager. Please disable it if you are using Pro Micros") | 54 | mm = True |
| 55 | for line in mm_check.stdout.split('\n'): | ||
| 56 | if 'ModemManager' in line and 'enabled' in line: | ||
| 57 | mm = False | ||
| 58 | |||
| 59 | if mm: | ||
| 60 | cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.") | ||
| 61 | |||
| 62 | else: | ||
| 63 | cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:') | ||
| 64 | cli.log.error(mm_check.stderr) | ||
| 65 | |||
| 52 | else: | 66 | else: |
| 53 | cli.log.warn("Can't find systemctl to check for ModemManager.") | 67 | cli.log.warn("Can't find systemctl to check for ModemManager.") |
| 68 | |||
| 54 | else: | 69 | else: |
| 55 | cli.log.info("Assuming {fg_cyan}Windows") | 70 | cli.log.info("Assuming {fg_cyan}Windows.") |
| 56 | 71 | ||
| 72 | # Report a summary of our findings to the user | ||
| 57 | if ok: | 73 | if ok: |
| 58 | cli.log.info('{fg_green}QMK is ready to go') | 74 | cli.log.info('{fg_green}QMK is ready to go') |
| 59 | else: | 75 | else: |
