# Path: confduino/boardlist.py
# def boards_txt(hwpack='arduino'):
#     """path of boards.txt."""
#     x = arduino_path() / 'hardware' / hwpack / 'boards.txt'
#     assert x.exists(), x
#     return x
# 
# def boards(hwpack='arduino'):
#     """read boards from boards.txt.
# 
#     :param core_package: 'all,'arduino',..
# 
#     """
#     bunch = read_properties(boards_txt(hwpack))
# 
#     bunch_items = list(bunch.items())
# 
#     # remove invalid boards
#     for bid, board in bunch_items:
#         if 'build' not in board.keys() or 'name' not in board.keys():
#             log.debug('invalid board found: %s', bid)
#             del bunch[bid]
# 
#     return bunch
# 
# Path: confduino/boardremove.py
# @entrypoint
# def remove_board(board_id):
#     """remove board.
# 
#     :param board_id: board id (e.g. 'diecimila')
#     :rtype: None
# 
#     """
# 
#     log.debug('remove %s', board_id)
#     lines = boards_txt().lines()
#     lines = filter(lambda x: not x.strip().startswith(board_id + '.'), lines)
#     boards_txt().write_lines(lines)
# 
# Path: confduino/util.py
# def bunch2properties(parent, data):
#     lines = []
#     try:
#         for key, value in data.items():
#             # recursive call
#             lines += bunch2properties(parent + '.' + key, value)
#     except AttributeError:
#         lines += [parent + '=' + str(data)]
#     return lines


from confduino.boardlist import boards_txt, boards
from confduino.boardremove import remove_board
from confduino.util import bunch2properties
import logging

log = logging.getLogger(__name__)

# TODO: how to pass options as cli argument?


def install_board(board_id, board_options, hwpack='arduino', replace_existing=False):
    """install board in boards.txt.

    :param board_id: string identifier
    :param board_options: dict like
    :param replace_existing: bool
    :rtype: None

    """
    doaction = 0

# Path: confduino/boardlist.py
# def boards_txt(hwpack='arduino'):
#     """path of boards.txt."""
#     x = arduino_path() / 'hardware' / hwpack / 'boards.txt'
#     assert x.exists(), x
#     return x
# 
# def boards(hwpack='arduino'):
#     """read boards from boards.txt.
# 
#     :param core_package: 'all,'arduino',..
# 
#     """
#     bunch = read_properties(boards_txt(hwpack))
# 
#     bunch_items = list(bunch.items())
# 
#     # remove invalid boards
#     for bid, board in bunch_items:
#         if 'build' not in board.keys() or 'name' not in board.keys():
#             log.debug('invalid board found: %s', bid)
#             del bunch[bid]
# 
#     return bunch
# 
# Path: confduino/boardremove.py
# @entrypoint
# def remove_board(board_id):
#     """remove board.
# 
#     :param board_id: board id (e.g. 'diecimila')
#     :rtype: None
# 
#     """
# 
#     log.debug('remove %s', board_id)
#     lines = boards_txt().lines()
#     lines = filter(lambda x: not x.strip().startswith(board_id + '.'), lines)
#     boards_txt().write_lines(lines)
# 
# Path: confduino/util.py
# def bunch2properties(parent, data):
#     lines = []
#     try:
#         for key, value in data.items():
#             # recursive call
#             lines += bunch2properties(parent + '.' + key, value)
#     except AttributeError:
#         lines += [parent + '=' + str(data)]
#     return lines


# Path: confduino/boardinstall.py
from confduino.boardlist import boards_txt, boards
from confduino.boardremove import remove_board
from confduino.util import bunch2properties
import logging


log = logging.getLogger(__name__)

# TODO: how to pass options as cli argument?


def install_board(board_id, board_options, hwpack='arduino', replace_existing=False):
    """install board in boards.txt.

    :param board_id: string identifier
    :param board_options: dict like
    :param replace_existing: bool
    :rtype: None

    """
    doaction = 0

    if board_id in boards(hwpack).keys():