Example #1
0
def fill_project_envs(  # pylint: disable=too-many-arguments,too-many-locals
        ctx, project_dir, board_ids, project_option, env_prefix,
        force_download):
    installed_boards = PlatformManager().get_installed_boards()
    content = []
    used_boards = []
    used_platforms = []

    config = util.load_project_config(project_dir)
    for section in config.sections():
        if not all(
            [section.startswith("env:"),
             config.has_option(section, "board")]):
            continue
        used_boards.append(config.get(section, "board"))

    for id_ in board_ids:
        manifest = None
        for boards in (installed_boards,
                       PlatformManager.get_registered_boards()):
            for b in boards:
                if b['id'] == id_:
                    manifest = b
                    break
        assert manifest is not None

        used_platforms.append(manifest['platform'])
        if id_ in used_boards:
            continue
        used_boards.append(id_)

        content.append("")
        content.append("[env:%s%s]" % (env_prefix, id_))
        content.append("platform = %s" % manifest['platform'])

        # find default framework for board
        frameworks = manifest.get("frameworks")
        if frameworks:
            content.append("framework = %s" % frameworks[0])

        content.append("board = %s" % id_)
        if project_option:
            content.extend(project_option)

    if force_download and used_platforms:
        _install_dependent_platforms(ctx, used_platforms)

    if not content:
        return

    with open(join(project_dir, "platformio.ini"), "a") as f:
        content.append("")
        f.write("\n".join(content))
Example #2
0
def validate_boards(ctx, param, value):  # pylint: disable=W0613
    pm = PlatformManager()
    # check installed boards
    known_boards = set([b['id'] for b in pm.get_installed_boards()])
    # if boards are not listed as installed, check registered boards
    if set(value) - known_boards:
        known_boards = set([b['id'] for b in pm.get_registered_boards()])
    unknown_boards = set(value) - known_boards
    try:
        assert not unknown_boards
        return value
    except AssertionError:
        raise click.BadParameter("%s. Please search for the board ID using "
                                 "`platformio boards` command" %
                                 ", ".join(unknown_boards))