doctor.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """QMK Python Doctor
  2. Check up for QMK environment.
  3. """
  4. import os
  5. import platform
  6. import shutil
  7. import subprocess
  8. from glob import glob
  9. from milc import cli
  10. @cli.subcommand('Basic QMK environment checks')
  11. def doctor(cli):
  12. """Basic QMK environment checks.
  13. This is currently very simple, it just checks that all the expected binaries are on your system.
  14. TODO(unclaimed):
  15. * [ ] Compile a trivial program with each compiler
  16. * [ ] Check for udev entries on linux
  17. """
  18. cli.log.info('QMK Doctor is checking your environment.')
  19. # Make sure the basic CLI tools we need are available and can be executed.
  20. binaries = ['dfu-programmer', 'avrdude', 'dfu-util', 'avr-gcc', 'arm-none-eabi-gcc']
  21. binaries += glob('bin/qmk-*')
  22. ok = True
  23. for binary in binaries:
  24. res = shutil.which(binary)
  25. if res is None:
  26. cli.log.error("{fg_red}QMK can't find %s in your path.", binary)
  27. ok = False
  28. else:
  29. try:
  30. subprocess.run([binary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, check=True)
  31. cli.log.info('Found {fg_cyan}%s', binary)
  32. except subprocess.CalledProcessError:
  33. cli.log.error("{fg_red}Can't run `%s --version`", binary)
  34. ok = False
  35. # Determine our OS and run platform specific tests
  36. OS = platform.system()
  37. if OS == "Darwin":
  38. cli.log.info("Detected {fg_cyan}macOS.")
  39. elif OS == "Linux":
  40. cli.log.info("Detected {fg_cyan}Linux.")
  41. if shutil.which('systemctl'):
  42. mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10, universal_newlines=True)
  43. if mm_check.returncode == 0:
  44. mm = True
  45. for line in mm_check.stdout.split('\n'):
  46. if 'ModemManager' in line and 'enabled' in line:
  47. mm = False
  48. if mm:
  49. cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.")
  50. else:
  51. cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:')
  52. cli.log.error(mm_check.stderr)
  53. else:
  54. cli.log.warn("Can't find systemctl to check for ModemManager.")
  55. else:
  56. cli.log.info("Assuming {fg_cyan}Windows.")
  57. # Report a summary of our findings to the user
  58. if ok:
  59. cli.log.info('{fg_green}QMK is ready to go')
  60. else:
  61. cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
  62. # FIXME(skullydazed): Link to a document about troubleshooting, or discord or something