Example #1
0
def handler_settings_get_all():
    """Handle the GET all settings requests.

    :return: JSON string with the formed response.
    """
    response_dict = {
            'response_type': 'settings',
            'response_state': 'full_response',
            'success': True,
            'settings_type': 'all',
            'settings': [{
                'settings_type': 'compiler',
                'selected': actions.get_compiler_path()
            }, {
                'settings_type': 'sketch',
                'selected': actions.get_sketch_path()
            }, {
                'settings_type': 'board',
                'options': [{'value': board, 'display_text': board}
                            for board in actions.get_arduino_boards()],
                'selected': actions.get_arduino_board_selected()
            }, {
                'settings_type': 'serial',
                'options': [{'value': k, 'display_text': v}
                            for k, v in iteritems(actions.get_serial_ports())],
                'selected': actions.get_serial_port_selected()
            }, {
                'settings_type': 'ide',
                'options': [{'value': k, 'display_text': v} for k, v in
                            iteritems(actions.get_load_ide_options())],
                'selected': actions.get_load_ide_selected()
            }]
        }
    set_header_no_cache()
    return response_dict
Example #2
0
    def test_get_arduino_board_selected(self, mock_settings):
        fake_board = 'not really a board'
        mock_settings.return_value.arduino_board = fake_board

        returned_board = actions.get_arduino_board_selected()

        self.assertEqual(returned_board, fake_board)
Example #3
0
def handler_settings_get_individual(name):
    """Handle the GET setting requests.

    Error codes:
    60 - Unexpected setting type requested.

    :param name: Setting value to retrieve.
    :return: JSON string with the formed response.
    """
    success = True
    response_dict = {
        'response_type': 'settings',
        'response_state': 'full_response',
        'settings_type': name
    }
    if name == 'compiler':
        response_dict.update({'selected': actions.get_compiler_path()})
    elif name == 'sketch':
        response_dict.update({'selected': actions.get_sketch_path()})
    elif name == 'board':
        response_dict.update({
            'options': [{
                'value': board,
                'display_text': board
            } for board in actions.get_arduino_boards()],
            'selected':
            actions.get_arduino_board_selected()
        })
    elif name == 'serial':
        response_dict.update({
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_serial_ports())],
            'selected':
            actions.get_serial_port_selected()
        })
    elif name == 'ide':
        response_dict.update({
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_load_ide_options())],
            'selected':
            actions.get_load_ide_selected()
        })
    else:
        success = False
        response_dict.update({
            'settings_type':
            'invalid',
            'errors': [{
                'id': 61,
                'description': 'Unexpected setting type requested.'
            }]
        })
    response_dict.update({'success': success})
    set_header_no_cache()
    return response_dict
Example #4
0
def handler_settings_get_all():
    """Handle the GET all settings requests.

    :return: JSON string with the formed response.
    """
    response_dict = {
        'response_type':
        'settings',
        'response_state':
        'full_response',
        'success':
        True,
        'settings_type':
        'all',
        'settings': [{
            'settings_type': 'compiler',
            'selected': actions.get_compiler_path()
        }, {
            'settings_type': 'sketch',
            'selected': actions.get_sketch_path()
        }, {
            'settings_type': 'examples',
            'selected': actions.get_examples_path()
        }, {
            'settings_type': 'board',
            'selected': actions.get_arduino_board_selected()
        }, {
            'settings_type': 'boardflag',
            'selected': actions.get_arduino_board_flag_selected()
        }, {
            'settings_type':
            'serial',
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_serial_ports())],
            'selected':
            actions.get_serial_port_selected()
        }, {
            'settings_type':
            'ide',
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_load_ide_options())],
            'selected':
            actions.get_load_ide_selected()
        }, {
            'settings_type':
            'baudrate',
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_baud_rate_options())],
            'selected':
            actions.get_baud_rate_selected()
        }, {
            'settings_type':
            'endofline',
            'options': [{
                'value': k,
                'display_text': v
            } for k, v in iteritems(actions.get_end_of_line_options())],
            'selected':
            actions.get_end_of_line_selected()
        }, {
            'settings_type': 'serialtimestamp',
            'selected': actions.get_serial_time_stamp()
        }, {
            'settings_type': 'loaddelay',
            'selected': actions.get_load_delay()
        }]
    }
    set_header_no_cache()
    return response_dict