Pathlib-ify qmk.keymap.list_keymaps()
This commit is contained in:
parent
3db41817e0
commit
512261b343
1 changed files with 10 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""Functions that help you work with QMK keymaps.
|
"""Functions that help you work with QMK keymaps.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import qmk.path
|
import qmk.path
|
||||||
import qmk.makefile
|
import qmk.makefile
|
||||||
|
@ -112,22 +113,22 @@ def list_keymaps(keyboard_name):
|
||||||
|
|
||||||
if rules_mk:
|
if rules_mk:
|
||||||
# qmk_firmware/keyboards
|
# qmk_firmware/keyboards
|
||||||
keyboards_dir = os.path.join(os.getcwd(), "keyboards")
|
keyboards_dir = Path.cwd() / "keyboards"
|
||||||
# path to the keyboard's directory
|
# path to the keyboard's directory
|
||||||
kb_path = os.path.join(keyboards_dir, keyboard_name)
|
kb_path = keyboards_dir / keyboard_name
|
||||||
# walk up the directory tree until keyboards_dir
|
# walk up the directory tree until keyboards_dir
|
||||||
# and collect all directories' name with keymap.c file in it
|
# and collect all directories' name with keymap.c file in it
|
||||||
while kb_path != keyboards_dir:
|
while kb_path != keyboards_dir:
|
||||||
keymaps_dir = os.path.join(kb_path, "keymaps")
|
keymaps_dir = kb_path / "keymaps"
|
||||||
if os.path.exists(keymaps_dir):
|
if keymaps_dir.exists():
|
||||||
names = names.union([keymap for keymap in os.listdir(keymaps_dir) if os.path.isfile(os.path.join(keymaps_dir, keymap, "keymap.c"))])
|
names = names.union([keymap for keymap in os.listdir(keymaps_dir) if (keymaps_dir / keymap / "keymap.c").is_file()])
|
||||||
kb_path = os.path.dirname(kb_path)
|
kb_path = kb_path.parent
|
||||||
|
|
||||||
# if community layouts are supported, get them
|
# if community layouts are supported, get them
|
||||||
if "LAYOUTS" in rules_mk:
|
if "LAYOUTS" in rules_mk:
|
||||||
for layout in rules_mk["LAYOUTS"].split():
|
for layout in rules_mk["LAYOUTS"].split():
|
||||||
cl_path = os.path.join(os.getcwd(), "layouts", "community", layout)
|
cl_path = Path.cwd() / "layouts" / "community" / layout
|
||||||
if os.path.exists(cl_path):
|
if cl_path.exists():
|
||||||
names = names.union([keymap for keymap in os.listdir(cl_path) if os.path.isfile(os.path.join(cl_path, keymap, "keymap.c"))])
|
names = names.union([keymap for keymap in os.listdir(cl_path) if (cl_path / keymap / "keymap.c").is_file()])
|
||||||
|
|
||||||
return sorted(names)
|
return sorted(names)
|
||||||
|
|
Loading…
Reference in a new issue