# Path: confduino/liblist.py
# def libraries_dir():
#     """return library root path.
# 
#     $ARDUINO/libraries
# 
#     """
#     x = arduino_path() / 'libraries'
#     assert x.exists(), x
#     return x
# 
# Path: confduino/util.py
# def tmpdir(directory=None, suffix=''):
#     x = tempfile.mkdtemp(suffix=suffix, prefix='confduino_', dir=directory)
#     return path(x)
# 
# def download(url):
#     log.debug('downloading %s', url)
#     f, _ = urllib.urlretrieve(url)
#     log.debug('downloaded file: %s', f)
#     return f
# 
# def clean_dir(root):
#     '''remove .* and _* files and directories under root'''
#     for x in root.walkdirs('.*', errors='ignore'):
#         x.rmtree()
#     for x in root.walkdirs('_*', errors='ignore'):
#         x.rmtree()
# 
#     for x in root.walkfiles('.*', errors='ignore'):
#         x.remove()
#     for x in root.walkfiles('_*', errors='ignore'):
#         x.remove()
# 
# class ConfduinoError(Exception):
#     pass


from confduino.liblist import libraries_dir
from confduino.util import tmpdir, download, clean_dir, ConfduinoError
from entrypoint2 import entrypoint
from path import Path as path
from pyunpack import Archive
import logging
    for i in range(len(lines)):
        if tester(lines[i]):
            change = True
            lines[i] = '// %s // disabled by confduino' % lines[i].strip()

    if change:
        filename.write_lines(lines)
    s = WPROGRAM + filename.text()
    filename.write_text(s)
#        print '\n'.join(lines)


def fix_wprogram_in_files(directory):
    """"""
    files = [x for x in directory.walk('*.h')]
    files += [x for x in directory.walk('*.cpp')]
    for f in files:
        if '"arduino.h"' not in f.text().lower():
            fix_wprogram_in_file(f)


@entrypoint
def install_lib(url, replace_existing=False, fix_wprogram=True):
    """install library from web or local files system.

    :param url: web address or file path
    :param replace_existing: bool
    :rtype: None

    """

# Path: confduino/liblist.py
# def libraries_dir():
#     """return library root path.
# 
#     $ARDUINO/libraries
# 
#     """
#     x = arduino_path() / 'libraries'
#     assert x.exists(), x
#     return x
# 
# Path: confduino/util.py
# def tmpdir(directory=None, suffix=''):
#     x = tempfile.mkdtemp(suffix=suffix, prefix='confduino_', dir=directory)
#     return path(x)
# 
# def download(url):
#     log.debug('downloading %s', url)
#     f, _ = urllib.urlretrieve(url)
#     log.debug('downloaded file: %s', f)
#     return f
# 
# def clean_dir(root):
#     '''remove .* and _* files and directories under root'''
#     for x in root.walkdirs('.*', errors='ignore'):
#         x.rmtree()
#     for x in root.walkdirs('_*', errors='ignore'):
#         x.rmtree()
# 
#     for x in root.walkfiles('.*', errors='ignore'):
#         x.remove()
#     for x in root.walkfiles('_*', errors='ignore'):
#         x.remove()
# 
# class ConfduinoError(Exception):
#     pass


# Path: confduino/libinstall.py
from confduino.liblist import libraries_dir
from confduino.util import tmpdir, download, clean_dir, ConfduinoError
from entrypoint2 import entrypoint
from path import Path as path
from pyunpack import Archive
import logging

    for i in range(len(lines)):
        if tester(lines[i]):
            change = True
            lines[i] = '// %s // disabled by confduino' % lines[i].strip()

    if change:
        filename.write_lines(lines)
    s = WPROGRAM + filename.text()
    filename.write_text(s)
#        print '\n'.join(lines)


def fix_wprogram_in_files(directory):
    """"""
    files = [x for x in directory.walk('*.h')]
    files += [x for x in directory.walk('*.cpp')]
    for f in files:
        if '"arduino.h"' not in f.text().lower():
            fix_wprogram_in_file(f)


@entrypoint
def install_lib(url, replace_existing=False, fix_wprogram=True):
    """install library from web or local files system.

    :param url: web address or file path
    :param replace_existing: bool
    :rtype: None

    """

    d = tmpdir(tmpdir())