diff options
author | Zach White <skullydazed@gmail.com> | 2021-06-22 11:50:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 19:50:53 +0100 |
commit | e87d23164522371b0c9560e81f36ed08caadc0ff (patch) | |
tree | 481bff93f77418ac7603d8ad4af492b4c86a02c2 /lib/python/qmk/cli/doctor.py | |
parent | d61e5c0027e289ccf48652afa4c442342e7ccf04 (diff) | |
download | qmk_firmware-e87d23164522371b0c9560e81f36ed08caadc0ff.tar.gz qmk_firmware-e87d23164522371b0c9560e81f36ed08caadc0ff.zip |
Refactor doctor.py into a directory (#13298)
Diffstat (limited to 'lib/python/qmk/cli/doctor.py')
-rwxr-xr-x | lib/python/qmk/cli/doctor.py | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py deleted file mode 100755 index 9e1057062..000000000 --- a/lib/python/qmk/cli/doctor.py +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | """QMK Doctor | ||
2 | |||
3 | Check out the user's QMK environment and make sure it's ready to compile. | ||
4 | """ | ||
5 | import platform | ||
6 | from subprocess import DEVNULL | ||
7 | |||
8 | from milc import cli | ||
9 | from milc.questions import yesno | ||
10 | from qmk import submodules | ||
11 | from qmk.constants import QMK_FIRMWARE | ||
12 | from qmk.os_helpers import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo | ||
13 | |||
14 | |||
15 | def os_tests(): | ||
16 | """Determine our OS and run platform specific tests | ||
17 | """ | ||
18 | platform_id = platform.platform().lower() | ||
19 | |||
20 | if 'darwin' in platform_id or 'macos' in platform_id: | ||
21 | return os_test_macos() | ||
22 | elif 'linux' in platform_id: | ||
23 | return os_test_linux() | ||
24 | elif 'windows' in platform_id: | ||
25 | return os_test_windows() | ||
26 | else: | ||
27 | cli.log.warning('Unsupported OS detected: %s', platform_id) | ||
28 | return CheckStatus.WARNING | ||
29 | |||
30 | |||
31 | def os_test_linux(): | ||
32 | """Run the Linux specific tests. | ||
33 | """ | ||
34 | # Don't bother with udev on WSL, for now | ||
35 | if 'microsoft' in platform.uname().release.lower(): | ||
36 | cli.log.info("Detected {fg_cyan}Linux (WSL){fg_reset}.") | ||
37 | |||
38 | # https://github.com/microsoft/WSL/issues/4197 | ||
39 | if QMK_FIRMWARE.as_posix().startswith("/mnt"): | ||
40 | cli.log.warning("I/O performance on /mnt may be extremely slow.") | ||
41 | return CheckStatus.WARNING | ||
42 | |||
43 | return CheckStatus.OK | ||
44 | else: | ||
45 | cli.log.info("Detected {fg_cyan}Linux{fg_reset}.") | ||
46 | from qmk.os_helpers.linux import check_udev_rules | ||
47 | |||
48 | return check_udev_rules() | ||
49 | |||
50 | |||
51 | def os_test_macos(): | ||
52 | """Run the Mac specific tests. | ||
53 | """ | ||
54 | cli.log.info("Detected {fg_cyan}macOS %s{fg_reset}.", platform.mac_ver()[0]) | ||
55 | |||
56 | return CheckStatus.OK | ||
57 | |||
58 | |||
59 | def os_test_windows(): | ||
60 | """Run the Windows specific tests. | ||
61 | """ | ||
62 | win32_ver = platform.win32_ver() | ||
63 | cli.log.info("Detected {fg_cyan}Windows %s (%s){fg_reset}.", win32_ver[0], win32_ver[1]) | ||
64 | |||
65 | return CheckStatus.OK | ||
66 | |||
67 | |||
68 | @cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.') | ||
69 | @cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.') | ||
70 | @cli.subcommand('Basic QMK environment checks') | ||
71 | def doctor(cli): | ||
72 | """Basic QMK environment checks. | ||
73 | |||
74 | This is currently very simple, it just checks that all the expected binaries are on your system. | ||
75 | |||
76 | TODO(unclaimed): | ||
77 | * [ ] Compile a trivial program with each compiler | ||
78 | """ | ||
79 | cli.log.info('QMK Doctor is checking your environment.') | ||
80 | cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE) | ||
81 | |||
82 | status = os_tests() | ||
83 | |||
84 | # Make sure our QMK home is a Git repo | ||
85 | git_ok = check_git_repo() | ||
86 | |||
87 | if git_ok == CheckStatus.WARNING: | ||
88 | cli.log.warning("QMK home does not appear to be a Git repository! (no .git folder)") | ||
89 | status = CheckStatus.WARNING | ||
90 | |||
91 | # Make sure the basic CLI tools we need are available and can be executed. | ||
92 | bin_ok = check_binaries() | ||
93 | |||
94 | if not bin_ok: | ||
95 | if yesno('Would you like to install dependencies?', default=True): | ||
96 | cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False) | ||
97 | bin_ok = check_binaries() | ||
98 | |||
99 | if bin_ok: | ||
100 | cli.log.info('All dependencies are installed.') | ||
101 | else: | ||
102 | status = CheckStatus.ERROR | ||
103 | |||
104 | # Make sure the tools are at the correct version | ||
105 | ver_ok = check_binary_versions() | ||
106 | if CheckStatus.ERROR in ver_ok: | ||
107 | status = CheckStatus.ERROR | ||
108 | elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK: | ||
109 | status = CheckStatus.WARNING | ||
110 | |||
111 | # Check out the QMK submodules | ||
112 | sub_ok = check_submodules() | ||
113 | |||
114 | if sub_ok == CheckStatus.OK: | ||
115 | cli.log.info('Submodules are up to date.') | ||
116 | else: | ||
117 | if yesno('Would you like to clone the submodules?', default=True): | ||
118 | submodules.update() | ||
119 | sub_ok = check_submodules() | ||
120 | |||
121 | if sub_ok == CheckStatus.ERROR: | ||
122 | status = CheckStatus.ERROR | ||
123 | elif sub_ok == CheckStatus.WARNING and status == CheckStatus.OK: | ||
124 | status = CheckStatus.WARNING | ||
125 | |||
126 | # Report a summary of our findings to the user | ||
127 | if status == CheckStatus.OK: | ||
128 | cli.log.info('{fg_green}QMK is ready to go') | ||
129 | return 0 | ||
130 | elif status == CheckStatus.WARNING: | ||
131 | cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found') | ||
132 | return 1 | ||
133 | else: | ||
134 | cli.log.info('{fg_red}Major problems detected, please fix these problems before proceeding.') | ||
135 | cli.log.info('{fg_blue}Check out the FAQ (https://docs.qmk.fm/#/faq_build) or join the QMK Discord (https://discord.gg/Uq7gcHh) for help.') | ||
136 | return 2 | ||