doctor.py 2.6 KB

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