def get_rules_mk(keyboard): """ Get a rules.mk for a keyboard Args: keyboard: name of the keyboard Raises: NoSuchKeyboardError: when the keyboard does not exists Returns: a dictionary with the content of the rules.mk file """ # Start with qmk_firmware/keyboards kb_path = Path.cwd() / "keyboards" # walk down the directory tree # and collect all rules.mk files kb_dir = kb_path / keyboard if kb_dir.exists(): rules_mk = dict() for directory in Path(keyboard).parts: kb_path = kb_path / directory rules_mk_path = kb_path / "rules.mk" if rules_mk_path.exists(): rules_mk = parse_rules_mk_file(rules_mk_path, rules_mk) else: raise NoSuchKeyboardError( "The requested keyboard and/or revision does not exist.") return rules_mk
def keymap(keyboard): """Locate the correct directory for storing a keymap. Args: keyboard The name of the keyboard. Example: clueboard/66/rev3 """ for directory in ['.', '..', '../..', '../../..', '../../../..', '../../../../..']: basepath = os.path.normpath(os.path.join('keyboards', keyboard, directory, 'keymaps')) if os.path.exists(basepath): return basepath logging.error('Could not find keymaps directory!') raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
def keymap(keyboard): """Locate the correct directory for storing a keymap. Args: keyboard The name of the keyboard. Example: clueboard/66/rev3 """ keyboard_folder = Path('keyboards') / keyboard for i in range(5): if (keyboard_folder / 'keymaps').exists(): return (keyboard_folder / 'keymaps').resolve() keyboard_folder = keyboard_folder.parent logging.error('Could not find the keymaps directory!') raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
def keymap(keyboard_name): """Locate the correct directory for storing a keymap. Args: keyboard_name The name of the keyboard. Example: clueboard/66/rev3 """ keyboard_folder = keyboard(keyboard_name) for _ in range(MAX_KEYBOARD_SUBFOLDERS): if (keyboard_folder / 'keymaps').exists(): return (keyboard_folder / 'keymaps').resolve() keyboard_folder = keyboard_folder.parent logging.error('Could not find the keymaps directory!') raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard_name)
def test_NoSuchKeyboardError(): try: raise NoSuchKeyboardError("test message") except NoSuchKeyboardError as e: assert e.message == 'test message'