summaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
authorskullydazed <skullydazed@users.noreply.github.com>2020-02-17 11:42:11 -0800
committerFlorian Didron <fdidron@users.noreply.github.com>2020-06-12 17:00:27 +0900
commit74bcafa2ded0f701abf5e34d38e456eac9a70f21 (patch)
tree1e1a40691bba7188daf6bab5b52985cbffaeccc3 /lib/python/qmk
parente28b21794ffeb884cfd15b595c131ca7d24f19f2 (diff)
Use pathlib everywhere we can (#7872)
* Use pathlib everywhere we can * Update lib/python/qmk/path.py Co-Authored-By: Erovia <Erovia@users.noreply.github.com> * Update lib/python/qmk/path.py Co-Authored-By: Erovia <Erovia@users.noreply.github.com> * Improvements based on @erovia's feedback * rework qmk compile and qmk flash to use pathlib * style * Remove the subcommand_name argument from find_keyboard_keymap() Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk')
-rw-r--r--lib/python/qmk/path.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py
index 64b2dc8350..d16928afb5 100644
--- a/lib/python/qmk/path.py
+++ b/lib/python/qmk/path.py
@@ -8,6 +8,35 @@ from qmk.constants import QMK_FIRMWARE, MAX_KEYBOARD_SUBFOLDERS
from qmk.errors import NoSuchKeyboardError
+def is_keymap_dir(keymap_path):
+ """Returns True if `keymap_path` is a valid keymap directory.
+ """
+ keymap_path = Path(keymap_path)
+ keymap_c = keymap_path / 'keymap.c'
+ keymap_json = keymap_path / 'keymap.json'
+
+ return any((keymap_c.exists(), keymap_json.exists()))
+
+
+def is_keyboard(keyboard_name):
+ """Returns True if `keyboard_name` is a keyboard we can compile.
+ """
+ keyboard_path = QMK_FIRMWARE / 'keyboards' / keyboard_name
+ rules_mk = keyboard_path / 'rules.mk'
+ return rules_mk.exists()
+
+
+def under_qmk_firmware():
+ """Returns a Path object representing the relative path under qmk_firmware, or None.
+ """
+ cwd = Path(os.environ['ORIG_CWD'])
+
+ try:
+ return cwd.relative_to(QMK_FIRMWARE)
+ except ValueError:
+ return None
+
+
def keymap(keyboard):
"""Locate the correct directory for storing a keymap.
@@ -39,5 +68,3 @@ def normpath(path):
return Path(path)
return Path(os.environ['ORIG_CWD']) / path
-
- return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))