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'])
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)