Exemplo n.º 1
0
def install_hwpack(url, replace_existing=False):
    """install hwpackrary from web or local files system.

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

    """
    d = tmpdir(tmpdir())
    f = download(url)
    Archive(f).extractall(d)

    clean_dir(d)
    src_dhwpack = find_hwpack_dir(d)

    targ_dhwpack = hwpack_dir() / src_dhwpack.name
    doaction = 0
    if targ_dhwpack.exists():
        log.debug('hwpack already exists: %s', targ_dhwpack)
        if replace_existing:
            log.debug('remove %s', targ_dhwpack)
            targ_dhwpack.rmtree()
            doaction = 1
    else:
        doaction = 1

    if doaction:
        log.debug('move %s -> %s', src_dhwpack, targ_dhwpack)
        src_dhwpack.move(targ_dhwpack)

        hwpack_dir().copymode(targ_dhwpack)
        for x in targ_dhwpack.walk():
            hwpack_dir().copymode(x)
Exemplo n.º 2
0
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())
    f = download(url)
    Archive(f).extractall(d)

    clean_dir(d)
    d, src_dlib = find_lib_dir(d)
    move_examples(d, src_dlib)
    fix_examples_dir(src_dlib)
    if fix_wprogram:
        fix_wprogram_in_files(src_dlib)

    targ_dlib = libraries_dir() / src_dlib.name
    if targ_dlib.exists():
        log.debug('library already exists: %s', targ_dlib)
        if replace_existing:
            log.debug('remove %s', targ_dlib)
            targ_dlib.rmtree()
        else:
            raise ConfduinoError('library already exists:' + targ_dlib)

    log.debug('move %s -> %s', src_dlib, targ_dlib)
    src_dlib.move(targ_dlib)

    libraries_dir().copymode(targ_dlib)
    for x in targ_dlib.walk():
        libraries_dir().copymode(x)
    return targ_dlib.name
Exemplo n.º 3
0
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())
    f = download(url)
    Archive(f).extractall(d)

    clean_dir(d)
    d, src_dlib = find_lib_dir(d)
    move_examples(d, src_dlib)
    fix_examples_dir(src_dlib)
    if fix_wprogram:
        fix_wprogram_in_files(src_dlib)

    targ_dlib = libraries_dir() / src_dlib.name
    if targ_dlib.exists():
        log.debug('library already exists: %s', targ_dlib)
        if replace_existing:
            log.debug('remove %s', targ_dlib)
            targ_dlib.rmtree()
        else:
            raise ConfduinoError('library already exists:' + targ_dlib)

    log.debug('move %s -> %s', src_dlib, targ_dlib)
    src_dlib.move(targ_dlib)

    libraries_dir().copymode(targ_dlib)
    for x in targ_dlib.walk():
        libraries_dir().copymode(x)
    return targ_dlib.name
Exemplo n.º 4
0
    def test_prog(self):
        d = tmpdir(suffix='_test')
        os.environ['ARDUINO_HOME'] = d
        programmers_txt = d / 'hardware' / 'arduino' / 'programmers.txt'

        programmers_txt.parent.makedirs()

        programmers_txt.write_text('')
        check_keys(programmers().keys(), [])

        programmers_txt.write_text('''
brd.x1.y1=foo
brd.x2=foo
brd.x3=foo
        ''')
        check_keys(programmers().keys(), ['brd'])

        install_programmer('ardu', dict(x1='hi'))
        check_keys(programmers().keys(), ['ardu', 'brd'])

        install_programmer('ardu', dict(x1='hi'))
        check_keys(programmers().keys(), ['ardu', 'brd'])

        remove_programmer('brd')
        check_keys(programmers().keys(), ['ardu'])
Exemplo n.º 5
0
 def test_version(self):
     d = tmpdir(suffix='_test')
     os.environ['ARDUINO_HOME'] = d
     (d / 'lib').makedirs()
     v = d / 'lib' / 'version.txt'
     v.write_text('0017')
     eq_(int(version()), 17)
     v.write_text('\n0018\n')
     eq_(int(version()), 18)
Exemplo n.º 6
0
 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'])
Exemplo n.º 7
0
    def test_boards(self):
        d = tmpdir(suffix='_test')
        os.environ['ARDUINO_HOME'] = d
        boards_txt = d / 'hardware' / 'arduino' / 'boards.txt'

        boards_txt.parent.makedirs()

        boards_txt.write_text('')
        eq_(board_names(), [])
        check_keys(boards().keys(), [])

        # invalid board
        boards_txt.write_text('''
brd.x3=foo
        ''')
        eq_(board_names(), [])

        boards_txt.write_text('''
brd.name=foo
brd.build=foo
brd.x3=foo
        ''')
        eq_(board_names(), ['brd'])
        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'])