summaryrefslogtreecommitdiff
path: root/lib/python/qmk/commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/commands.py')
-rw-r--r--lib/python/qmk/commands.py20
1 files changed, 20 insertions, 0 deletions
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)