示例#1
0
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    FIXME(skullydazed): add code to check and warn if the keymap already exists

    If --keyboard and --keymap are provided this command will build a firmware based on that.

    """
    if cli.args.filename:
        # Parse the configurator json
        user_keymap = parse_configurator_json(cli.args.filename)

        # Generate the keymap
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)

        # Compile the keymap
        command = compile_configurator_json(user_keymap)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])

    elif cli.config.compile.keyboard and cli.config.compile.keymap:
        # Generate the make command for a specific keyboard/keymap.
        command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap)

    else:
        cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`.')
        return False

    cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
    subprocess.run(command)
示例#2
0
def keymap_json_config(keyboard, keymap):
    """Extract keymap level config
    """
    keymap_folder = locate_keymap(keyboard, keymap).parent

    km_info_json = parse_configurator_json(keymap_folder / 'keymap.json')
    return km_info_json.get('config', {})
示例#3
0
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    If a keyboard and keymap are provided this command will build a firmware based on that.
    """
    if cli.args.clean and not cli.args.filename and not cli.args.dry_run:
        command = create_make_command(cli.config.compile.keyboard,
                                      cli.config.compile.keymap, 'clean')
        cli.run(command, capture_output=False, stdin=DEVNULL)

    # Build the environment vars
    envs = {}
    for env in cli.args.env:
        if '=' in env:
            key, value = env.split('=', 1)
            envs[key] = value
        else:
            cli.log.warning('Invalid environment variable: %s', env)

    # Determine the compile command
    command = None

    if cli.args.filename:
        # If a configurator JSON was provided generate a keymap and compile it
        user_keymap = parse_configurator_json(cli.args.filename)
        command = compile_configurator_json(
            user_keymap, parallel=cli.config.compile.parallel, **envs)

    else:
        if cli.config.compile.keyboard and cli.config.compile.keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(cli.config.compile.keyboard,
                                          cli.config.compile.keymap,
                                          parallel=cli.config.compile.parallel,
                                          **envs)

        elif not cli.config.compile.keyboard:
            cli.log.error('Could not determine keyboard!')
        elif not cli.config.compile.keymap:
            cli.log.error('Could not determine keymap!')

    # Compile the firmware, if we're able to
    if command:
        cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
        if not cli.args.dry_run:
            cli.echo('\n')
            # FIXME(skullydazed/anyone): Remove text=False once milc 1.0.11 has had enough time to be installed everywhere.
            compile = cli.run(command, capture_output=False, text=False)
            return compile.returncode

    else:
        cli.log.error(
            'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
        )
        cli.echo(
            'usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]'
        )
        return False
示例#4
0
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    If a keyboard and keymap are provided this command will build a firmware based on that.
    """
    if cli.args.filename:
        # If a configurator JSON was provided skip straight to compiling it
        # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap.
        user_keymap = parse_configurator_json(cli.args.filename)
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        command = compile_configurator_json(user_keymap)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path,
                     user_keymap['keymap'])

    else:
        # Perform the action the user specified
        user_keyboard, user_keymap = find_keyboard_keymap()
        if user_keyboard and user_keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(user_keyboard, user_keymap)

        else:
            cli.log.error(
                'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
            )
            cli.echo(
                'usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]'
            )
            return False

    cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
    subprocess.run(command)
示例#5
0
def json2c(cli):
    """Generate a keymap.c from a configurator export.

    This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided.
    """

    # Parse the configurator from json file (or stdin)
    user_keymap = parse_configurator_json(cli.args.filename)

    # Environment processing
    if cli.args.output and cli.args.output.name == '-':
        cli.args.output = None

    # Generate the keymap
    keymap_c = qmk.keymap.generate_c(user_keymap)

    if cli.args.output:
        cli.args.output.parent.mkdir(parents=True, exist_ok=True)
        if cli.args.output.exists():
            cli.args.output.replace(cli.args.output.parent /
                                    (cli.args.output.name + '.bak'))
        cli.args.output.write_text(keymap_c)

        if not cli.args.quiet:
            cli.log.info('Wrote keymap to %s.', cli.args.output)

    else:
        print(keymap_c)
示例#6
0
def flash(cli):
    """Compile and or flash QMK Firmware or keyboard/layout

    If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
    will be ignored.

    If no file is supplied, keymap and keyboard are expected.

    If bootloader is omitted the make system will use the configured bootloader for that keyboard.
    """
    command = ''

    if cli.args.bootloaders:
        # Provide usage and list bootloaders
        cli.echo(
            'usage: qmk flash [-h] [-b] [-n] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
        )
        print_bootloader_help()
        return False

    if cli.args.filename:
        # Handle compiling a configurator JSON
        user_keymap = parse_configurator_json(cli.args.filename)
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        command = compile_configurator_json(user_keymap, cli.args.bootloader)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path,
                     user_keymap['keymap'])

    else:
        if cli.config.flash.keyboard and cli.config.flash.keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(cli.config.flash.keyboard,
                                          cli.config.flash.keymap,
                                          cli.args.bootloader)

        elif not cli.config.flash.keyboard:
            cli.log.error('Could not determine keyboard!')
        elif not cli.config.flash.keymap:
            cli.log.error('Could not determine keymap!')

    # Compile the firmware, if we're able to
    if command:
        cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
        if not cli.args.dry_run:
            cli.echo('\n')
            compile = subprocess.run(command)
            return compile.returncode

    else:
        cli.log.error(
            'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
        )
        cli.echo(
            'usage: qmk flash [-h] [-b] [-n] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
        )
        return False
示例#7
0
def _find_via_layout_macro(keyboard):
    keymap_layout = None
    if 'via' in list_keymaps(keyboard):
        keymap_path = locate_keymap(keyboard, 'via')
        if keymap_path.suffix == '.json':
            keymap_layout = parse_configurator_json(keymap_path)['layout']
        else:
            keymap_layout = parse_keymap_c(keymap_path)['layers'][0]['layout']
    return keymap_layout
示例#8
0
def flash(cli):
    """Compile and or flash QMK Firmware or keyboard/layout

    If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
    will be ignored.

    If no file is supplied, keymap and keyboard are expected.

    If bootloader is omitted, the one according to the rules.mk will be used.

    """
    command = []
    if cli.args.bootloaders:
        # Provide usage and list bootloaders
        cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
        print_bootloader_help()
        return False

    elif cli.args.keymap and not cli.args.keyboard:
        # If only a keymap was given but no keyboard, suggest listing keyboards
        cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
        cli.log.error('run \'qmk list_keyboards\' to find out the supported keyboards')
        return False

    elif cli.args.filename:
        # Get keymap path to log info
        user_keymap = parse_configurator_json(cli.args.filename)
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])

        cli.log.info('Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s', user_keymap['keymap'], keymap_path)

        # Convert the JSON into a C file and write it to disk.
        command = compile_configurator_json(user_keymap, cli.args.bootloader)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap'])

    elif cli.args.keyboard and cli.args.keymap:
        # Generate the make command for a specific keyboard/keymap.
        command = create_make_command(cli.config.flash.keyboard, cli.config.flash.keymap, cli.args.bootloader)

    else:
        cli.echo('usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]')
        cli.log.error('You must supply a configurator export or both `--keyboard` and `--keymap`. You can also specify a bootloader with --bootloader. Use --bootloaders to list the available bootloaders.')
        return False

    cli.log.info('Flashing keymap with {fg_cyan}%s\n\n', ' '.join(command))
    subprocess.run(command)
示例#9
0
def flash(cli):
    """Compile and or flash QMK Firmware or keyboard/layout

    If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
    will be ignored.

    If no file is supplied, keymap and keyboard are expected.

    If bootloader is omitted, the one according to the rules.mk will be used.

    """
    if cli.args.bootloaders:
        # Provide usage and list bootloaders
        cli.echo(
            'usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
        )
        print_bootloader_help()
        return False

    if cli.args.filename:
        # Handle compiling a configurator JSON
        user_keymap = parse_configurator_json(cli.args.filename)
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        command = compile_configurator_json(user_keymap, cli.args.bootloader)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path,
                     user_keymap['keymap'])

    else:
        # Perform the action the user specified
        user_keyboard, user_keymap = find_keyboard_keymap()
        if user_keyboard and user_keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(user_keyboard, user_keymap,
                                          cli.args.bootloader)

        else:
            cli.log.error(
                'You must supply a configurator export or both `--keyboard` and `--keymap`.'
            )
            cli.echo(
                'usage: qmk flash [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
            )
            return False

    cli.log.info('Flashing keymap with {fg_cyan}%s\n\n', ' '.join(command))
    subprocess.run(command)
示例#10
0
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    If a keyboard and keymap are provided this command will build a firmware based on that.
    """
    command = None

    if cli.args.filename:
        # If a configurator JSON was provided generate a keymap and compile it
        # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap.
        user_keymap = parse_configurator_json(cli.args.filename)
        command = compile_configurator_json(user_keymap)

    else:
        if cli.config.compile.keyboard and cli.config.compile.keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(cli.config.compile.keyboard,
                                          cli.config.compile.keymap)

        elif not cli.config.compile.keyboard:
            cli.log.error('Could not determine keyboard!')
        elif not cli.config.compile.keymap:
            cli.log.error('Could not determine keymap!')

    # Compile the firmware, if we're able to
    if command:
        cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
        if not cli.args.dry_run:
            cli.echo('\n')
            compile = subprocess.run(command)
            return compile.returncode

    else:
        cli.log.error(
            'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
        )
        cli.echo(
            'usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]'
        )
        return False
示例#11
0
def flash(cli):
    """Compile and or flash QMK Firmware or keyboard/layout

    If a Configurator JSON export is supplied this command will create a new keymap. Keymap and Keyboard arguments
    will be ignored.

    If no file is supplied, keymap and keyboard are expected.

    If bootloader is omitted the make system will use the configured bootloader for that keyboard.
    """
    if cli.args.clean and not cli.args.filename and not cli.args.dry_run:
        command = create_make_command(cli.config.flash.keyboard,
                                      cli.config.flash.keymap, 'clean')
        cli.run(command, capture_output=False, stdin=DEVNULL)

    # Build the environment vars
    envs = {}
    for env in cli.args.env:
        if '=' in env:
            key, value = env.split('=', 1)
            envs[key] = value
        else:
            cli.log.warning('Invalid environment variable: %s', env)

    # Determine the compile command
    command = ''

    if cli.args.bootloaders:
        # Provide usage and list bootloaders
        cli.echo(
            'usage: qmk flash [-h] [-b] [-n] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
        )
        print_bootloader_help()
        return False

    if cli.args.filename:
        # Handle compiling a configurator JSON
        user_keymap = parse_configurator_json(cli.args.filename)
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        command = compile_configurator_json(user_keymap,
                                            cli.args.bootloader,
                                            parallel=cli.config.flash.parallel,
                                            **envs)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path,
                     user_keymap['keymap'])

    else:
        if cli.config.flash.keyboard and cli.config.flash.keymap:
            # Generate the make command for a specific keyboard/keymap.
            command = create_make_command(cli.config.flash.keyboard,
                                          cli.config.flash.keymap,
                                          cli.args.bootloader,
                                          parallel=cli.config.flash.parallel,
                                          **envs)

        elif not cli.config.flash.keyboard:
            cli.log.error('Could not determine keyboard!')
        elif not cli.config.flash.keymap:
            cli.log.error('Could not determine keymap!')

    # Compile the firmware, if we're able to
    if command:
        cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command))
        if not cli.args.dry_run:
            cli.echo('\n')
            compile = cli.run(command, capture_output=False, stdin=DEVNULL)
            return compile.returncode

    else:
        cli.log.error(
            'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
        )
        cli.echo(
            'usage: qmk flash [-h] [-b] [-n] [-kb KEYBOARD] [-km KEYMAP] [-bl BOOTLOADER] [filename]'
        )
        return False
示例#12
0
def compile(cli):
    """Compile a QMK Firmware.

    If a Configurator export is supplied this command will create a new keymap, overwriting an existing keymap if one exists.

    FIXME(skullydazed): add code to check and warn if the keymap already exists

    If --keyboard and --keymap are provided this command will build a firmware based on that.

    """
    # Set CWD as directory command was issued from
    cwd = os.environ['ORIG_CWD']
    qmk_path = os.getcwd()
    current_folder = os.path.basename(cwd)
    # Initialize boolean to check for being in a keyboard directory and initialize keyboard string
    in_keyboard = False
    in_layout = False
    keyboard = ""
    keymap = ""
    user_keymap = ""
    user_keyboard = ""

    # Set path for '/keyboards/' directory
    keyboards_path = os.path.join(qmk_path, "keyboards")
    layouts_path = os.path.join(qmk_path, "layouts")

    # If below 'keyboards' and not in 'keyboards' or 'keymaps', get current keyboard name
    if cwd.startswith(keyboards_path):
        if current_folder != "keyboards" and current_folder != "keymaps":
            if os.path.basename(os.path.abspath(os.path.join(
                    cwd, ".."))) == "keymaps":
                # If in a keymap folder, set relative path, get everything before /keymaps, and the keymap name
                relative_path = cwd[len(keyboards_path):][1:]
                keyboard = str(relative_path).split("/keymaps", 1)[0]
                keymap = str(relative_path.rsplit("/", 1)[-1])
            else:
                keyboard = str(cwd[len(keyboards_path):])[1:]

            in_keyboard = True

    # If in layouts dir
    if cwd.startswith(layouts_path):
        if current_folder != "layouts":
            in_layout = True

    # If user keyboard/keymap or compile keyboard/keymap are supplied, assign those
    if cli.config.compile.keyboard:
        user_keyboard = cli.config.compile.keyboard
    if cli.config.compile.keymap and not in_layout:
        user_keymap = cli.config.compile.keymap

    if cli.args.filename:
        # Parse the configurator json
        user_keymap = parse_configurator_json(cli.args.filename)

        # Generate the keymap
        keymap_path = qmk.path.keymap(user_keymap['keyboard'])
        cli.log.info(
            'Creating {fg_cyan}%s{style_reset_all} keymap in {fg_cyan}%s',
            user_keymap['keymap'], keymap_path)

        # Compile the keymap
        command = compile_configurator_json(cli.args.filename)

        cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path,
                     user_keymap['keymap'])

    elif user_keyboard and user_keymap:
        # Generate the make command for a specific keyboard/keymap.
        command = create_make_command(user_keyboard, user_keymap)

    elif in_keyboard:
        keyboard = user_keyboard if user_keyboard else keyboard
        keymap = user_keymap if user_keymap else keymap

        if not os.path.exists(
                os.path.join(keyboards_path, keyboard, "rules.mk")):
            cli.log.error(
                'This directory does not contain a rules.mk file. Change directory or supply --keyboard with optional --keymap'
            )
            return False

        # Get path for keyboard directory
        keymap_path = qmk.path.keymap(keyboard)

        # Check for global keymap config first
        if keymap:
            command = create_make_command(keyboard, keymap)

        else:
            # If no default keymap exists and none provided
            cli.log.error(
                'This directory does not contain a keymap. Set one with `qmk config` or supply `--keymap` '
            )
            return False

    elif in_layout:
        if user_keyboard:
            keymap = current_folder
            command = create_make_command(user_keyboard, keymap)
        else:
            cli.log.error(
                'You must supply a keyboard to compile a layout keymap. Set one with `qmk config` or supply `--keyboard` '
            )
            return False

    else:
        cli.log.error(
            'You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.'
        )
        return False

    cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command))
    subprocess.run(command)