diff options
-rw-r--r-- | lib/python/qmk/path.py | 31 |
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)) |