doctor.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.entrypoint('Basic QMK environment checks')
  11. def main(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. except subprocess.CalledProcessError:
  32. cli.log.error("{fg_red}Can't run `%s --version`", binary)
  33. ok = False
  34. # Determine our OS and run platform specific tests
  35. OS = platform.system()
  36. if OS == "Darwin":
  37. cli.log.info("Detected {fg_cyan}macOS.")
  38. elif OS == "Linux":
  39. cli.log.info("Detected {fg_cyan}Linux.")
  40. if shutil.which('systemctl'):
  41. mm_check = subprocess.run(['systemctl', 'list-unit-files'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=10)
  42. if mm_check.returncode == 0:
  43. mm = True
  44. for line in mm_check.stdout.split('\n'):
  45. if 'ModemManager' in line and 'enabled' in line:
  46. mm = False
  47. if mm:
  48. cli.log.warn("{bg_yellow}Detected ModemManager. Please disable it if you are using a Pro-Micro.")
  49. else:
  50. cli.log.error('{bg_red}Could not run `systemctl list-unit-files`:')
  51. cli.log.error(mm_check.stderr)
  52. else:
  53. cli.log.warn("Can't find systemctl to check for ModemManager.")
  54. else:
  55. cli.log.info("Assuming {fg_cyan}Windows.")
  56. # Report a summary of our findings to the user
  57. if ok:
  58. cli.log.info('{fg_green}QMK is ready to go')
  59. else:
  60. cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
  61. # FIXME(skullydazed): Link to a document about troubleshooting, or discord or something