# Path: confduino/boardinstall.py
# 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():
#         log.debug('board already exists: %s', board_id)
#         if replace_existing:
#             log.debug('remove board: %s' , board_id)
#             remove_board(board_id)
#             doaction = 1
#     else:
#         doaction = 1
# 
#     if doaction:
#         lines = bunch2properties(board_id, board_options)
#         boards_txt().write_lines([''] + lines, append=1)
# 
# Path: confduino/boardlist.py
# def board_names(hwpack='arduino'):
#     """return installed board names."""
#     ls = list(boards(hwpack).keys())
#     ls.sort()
#     return ls
# 
# Path: confduino/boardlist.py
# 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/hwpacklist.py
# def hwpack_names():
#     """return installed hardware package names."""
#     ls = hwpack_dir().listdir()
#     ls = [x.name for x in ls]
#     ls = [x for x in ls if x != 'tools']
#     arduino_included = 'arduino' in ls
#     ls = [x for x in ls if x != 'arduino']
#     ls.sort()
#     if arduino_included:
#         ls = ['arduino'] + ls  # move to 1st pos
#     return ls
# 
# Path: confduino/proginstall.py
# def install_programmer(programmer_id, programmer_options, replace_existing=False):
#     """install programmer in programmers.txt.
# 
#     :param programmer_id: string identifier
#     :param programmer_options: dict like
#     :param replace_existing: bool
#     :rtype: None
# 
#     """
#     doaction = 0
#     if programmer_id in programmers().keys():
#         log.debug('programmer already exists: %s', programmer_id)
#         if replace_existing:
#             log.debug('remove programmer: %s', programmer_id)
#             remove_programmer(programmer_id)
#             doaction = 1
#     else:
#         doaction = 1
# 
#     if doaction:
#         lines = bunch2properties(programmer_id, programmer_options)
#         programmers_txt().write_lines([''] + lines, append=1)
# 
# Path: confduino/proglist.py
# def programmers():
#     """read programmers from programmers.txt."""
#     return read_properties(programmers_txt())
# 
# Path: confduino/progremove.py
# @entrypoint
# def remove_programmer(programmer_id):
#     """remove programmer.
# 
#     :param programmer_id: programmer id (e.g. 'avrisp')
#     :rtype: None
# 
#     """
# 
#     log.debug('remove %s', programmer_id)
#     lines = programmers_txt().lines()
#     lines = filter(
#         lambda x: not x.strip().startswith(programmer_id + '.'), lines)
#     programmers_txt().write_lines(lines)
# 
# Path: confduino/util.py
# def tmpdir(directory=None, suffix=''):
#     x = tempfile.mkdtemp(suffix=suffix, prefix='confduino_', dir=directory)
#     return path(x)
# 
# Path: confduino/version.py
# def version():
#     """return version as string.
# 
#     example: 0022
# 
#     """
#     return version_txt().text().strip()


from confduino.boardinstall import install_board
from confduino.boardlist import board_names
from confduino.boardlist import boards
from confduino.boardremove import remove_board
from confduino.hwpacklist import hwpack_names
from confduino.proginstall import install_programmer
from confduino.proglist import programmers
from confduino.progremove import remove_programmer
from confduino.util import tmpdir
from confduino.version import version
from nose.tools import eq_
from unittest import TestCase
import os
        check_keys(boards().keys(), ['brd'])

        # invalid
        install_board('ardu', dict(x1='hi'))
        eq_(board_names(), ['brd'])

        install_board('ardu', dict(name='hi', build=1))
        eq_(set(board_names()), set(['brd', 'ardu']))

        install_board('ardu', dict(x1='hi'))
        eq_(set(board_names()), set(['brd', 'ardu']))

        remove_board('brd')
        eq_(board_names(), ['ardu'])

    def test_packs(self):
        d = tmpdir(suffix='_test')
        os.environ['ARDUINO_HOME'] = d
        (d / 'hardware').makedirs()
        eq_(hwpack_names(), [])
        boards_txt = d / 'hardware' / 'p1' / 'boards.txt'
        boards_txt.parent.makedirs()
        boards_txt.write_text('')
        eq_(hwpack_names(), ['p1'])
        boards_txt = d / 'hardware' / 'p2' / 'boards.txt'
        boards_txt.parent.makedirs()
        boards_txt.write_text('')
        eq_(hwpack_names(), ['p1', 'p2'])

    def test_version(self):

# Path: confduino/boardinstall.py
# 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():
#         log.debug('board already exists: %s', board_id)
#         if replace_existing:
#             log.debug('remove board: %s' , board_id)
#             remove_board(board_id)
#             doaction = 1
#     else:
#         doaction = 1
# 
#     if doaction:
#         lines = bunch2properties(board_id, board_options)
#         boards_txt().write_lines([''] + lines, append=1)
# 
# Path: confduino/boardlist.py
# def board_names(hwpack='arduino'):
#     """return installed board names."""
#     ls = list(boards(hwpack).keys())
#     ls.sort()
#     return ls
# 
# Path: confduino/boardlist.py
# 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/hwpacklist.py
# def hwpack_names():
#     """return installed hardware package names."""
#     ls = hwpack_dir().listdir()
#     ls = [x.name for x in ls]
#     ls = [x for x in ls if x != 'tools']
#     arduino_included = 'arduino' in ls
#     ls = [x for x in ls if x != 'arduino']
#     ls.sort()
#     if arduino_included:
#         ls = ['arduino'] + ls  # move to 1st pos
#     return ls
# 
# Path: confduino/proginstall.py
# def install_programmer(programmer_id, programmer_options, replace_existing=False):
#     """install programmer in programmers.txt.
# 
#     :param programmer_id: string identifier
#     :param programmer_options: dict like
#     :param replace_existing: bool
#     :rtype: None
# 
#     """
#     doaction = 0
#     if programmer_id in programmers().keys():
#         log.debug('programmer already exists: %s', programmer_id)
#         if replace_existing:
#             log.debug('remove programmer: %s', programmer_id)
#             remove_programmer(programmer_id)
#             doaction = 1
#     else:
#         doaction = 1
# 
#     if doaction:
#         lines = bunch2properties(programmer_id, programmer_options)
#         programmers_txt().write_lines([''] + lines, append=1)
# 
# Path: confduino/proglist.py
# def programmers():
#     """read programmers from programmers.txt."""
#     return read_properties(programmers_txt())
# 
# Path: confduino/progremove.py
# @entrypoint
# def remove_programmer(programmer_id):
#     """remove programmer.
# 
#     :param programmer_id: programmer id (e.g. 'avrisp')
#     :rtype: None
# 
#     """
# 
#     log.debug('remove %s', programmer_id)
#     lines = programmers_txt().lines()
#     lines = filter(
#         lambda x: not x.strip().startswith(programmer_id + '.'), lines)
#     programmers_txt().write_lines(lines)
# 
# Path: confduino/util.py
# def tmpdir(directory=None, suffix=''):
#     x = tempfile.mkdtemp(suffix=suffix, prefix='confduino_', dir=directory)
#     return path(x)
# 
# Path: confduino/version.py
# def version():
#     """return version as string.
# 
#     example: 0022
# 
#     """
#     return version_txt().text().strip()


# Path: tests/test.py
from confduino.boardinstall import install_board
from confduino.boardlist import board_names
from confduino.boardlist import boards
from confduino.boardremove import remove_board
from confduino.hwpacklist import hwpack_names
from confduino.proginstall import install_programmer
from confduino.proglist import programmers
from confduino.progremove import remove_programmer
from confduino.util import tmpdir
from confduino.version import version
from nose.tools import eq_
from unittest import TestCase
import os

        check_keys(boards().keys(), ['brd'])

        # invalid
        install_board('ardu', dict(x1='hi'))
        eq_(board_names(), ['brd'])

        install_board('ardu', dict(name='hi', build=1))
        eq_(set(board_names()), set(['brd', 'ardu']))

        install_board('ardu', dict(x1='hi'))
        eq_(set(board_names()), set(['brd', 'ardu']))

        remove_board('brd')
        eq_(board_names(), ['ardu'])

    def test_packs(self):
        d = tmpdir(suffix='_test')
        os.environ['ARDUINO_HOME'] = d
        (d / 'hardware').makedirs()
        eq_(hwpack_names(), [])
        boards_txt = d / 'hardware' / 'p1' / 'boards.txt'
        boards_txt.parent.makedirs()
        boards_txt.write_text('')
        eq_(hwpack_names(), ['p1'])
        boards_txt = d / 'hardware' / 'p2' / 'boards.txt'
        boards_txt.parent.makedirs()
        boards_txt.write_text('')
        eq_(hwpack_names(), ['p1', 'p2'])

    def test_version(self):

        d = tmpdir(suffix='_test')