summaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk')
-rwxr-xr-xlib/python/qmk/cli/doctor.py17
-rw-r--r--lib/python/qmk/commands.py20
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py3
3 files changed, 31 insertions, 9 deletions
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py
index 9b81c8508b..65b6f0a96f 100755
--- a/lib/python/qmk/cli/doctor.py
+++ b/lib/python/qmk/cli/doctor.py
@@ -10,6 +10,7 @@ from pathlib import Path
from milc import cli
from qmk import submodules
from qmk.questions import yesno
+from qmk.commands import run
ESSENTIAL_BINARIES = {
'dfu-programmer': {},
@@ -135,7 +136,7 @@ def check_modem_manager():
"""Returns True if ModemManager is running.
"""
if shutil.which("systemctl"):
- mm_check = subprocess.run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
+ mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
if mm_check.returncode == 0:
return True
@@ -153,7 +154,7 @@ def is_executable(command):
return False
# Make sure the command can be executed
- check = subprocess.run([command, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, universal_newlines=True)
+ check = run([command, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=5, universal_newlines=True)
ESSENTIAL_BINARIES[command]['output'] = check.stdout
if check.returncode in [0, 1]: # Older versions of dfu-programmer exit 1
@@ -207,19 +208,19 @@ def doctor(cli):
ok = True
# Determine our OS and run platform specific tests
- OS = platform.platform().lower() # noqa (N806), uppercase name is ok in this instance
+ platform_id = platform.platform().lower()
- if 'darwin' in OS or 'macos' in OS:
+ if 'darwin' in platform_id or 'macos' in platform_id:
if not os_test_macos():
ok = False
- elif 'linux' in OS:
+ elif 'linux' in platform_id:
if not os_test_linux():
ok = False
- elif 'windows' in OS:
+ elif 'windows' in platform_id:
if not os_test_windows():
ok = False
else:
- cli.log.error('Unsupported OS detected: %s', OS)
+ cli.log.error('Unsupported OS detected: %s', platform_id)
ok = False
# Make sure the basic CLI tools we need are available and can be executed.
@@ -227,7 +228,7 @@ def doctor(cli):
if not bin_ok:
if yesno('Would you like to install dependencies?', default=True):
- subprocess.run(['util/qmk_install.sh'])
+ run(['util/qmk_install.sh'])
bin_ok = check_binaries()
if bin_ok:
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index 3d4ed16163..3424cdf085 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -1,6 +1,10 @@
"""Helper functions for commands.
"""
import json
+import os
+import platform
+import subprocess
+import shlex
import qmk.keymap
@@ -61,3 +65,19 @@ def parse_configurator_json(configurator_file):
user_keymap = json.load(configurator_file)
return user_keymap
+
+
+def run(command, *args, **kwargs):
+ """Run a command with subprocess.run
+ """
+ platform_id = platform.platform().lower()
+
+ if isinstance(command, str):
+ raise TypeError('`command` must be a non-text sequence such as list or tuple.')
+
+ if 'windows' in platform_id:
+ safecmd = map(shlex.quote, command)
+ safecmd = ' '.join(safecmd)
+ command = [os.environ['SHELL'], '-c', safecmd]
+
+ return subprocess.run(command, *args, **kwargs)
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index a2595eb788..3b4e66a211 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -1,9 +1,10 @@
import subprocess
+from qmk.commands import run
def check_subcommand(command, *args):
cmd = ['bin/qmk', command] + list(args)
- return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+ return run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
def test_cformat():