<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> from . import base <EOL> class TargetBoardInfo ( object ) : <EOL> def __init__ ( self , root_dirs ) : <EOL> self . target_board = None <EOL> self . target_sub_boards = [ ] <EOL> self . settings = base . settings . get_arduino_settings ( ) <EOL> self . update ( root_dirs ) <EOL> def update ( self , root_dirs ) : <EOL> self . root_dirs = root_dirs <EOL> self . check_target_board ( ) <EOL> def check_target_board ( self ) : <EOL> boards = load_boards ( self . root_dirs ) <EOL> if boards : <EOL> board_ids = [ board . get_id ( ) for board in boards ] <EOL> target_board_id = self . settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not target_board_id in board_ids : <EOL> target_board_id = board_ids [ <NUM_LIT:0> ] <EOL> self . settings . set ( '<STR_LIT>' , target_board_id ) <EOL> index = board_ids . index ( target_board_id ) <EOL> self . target_board = boards [ index ] <EOL> self . target_sub_boards = [ ] <EOL> if self . target_board . has_options ( ) : <EOL> self . check_target_sub_boards ( ) <EOL> def check_target_sub_boards ( self ) : <EOL> self . target_sub_boards = [ ] <EOL> if self . target_board and self . target_board . has_options ( ) : <EOL> target_board_id = self . target_board . get_id ( ) <EOL> board_options = self . target_board . get_options ( ) <EOL> for option_index , option in enumerate ( board_options ) : <EOL> target_sub_board_info = TargetSubBoardInfo ( self . target_board , <EOL> option_index ) <EOL> target_sub_board = target_sub_board_info . get_target_sub_board ( ) <EOL> self . target_sub_boards . append ( target_sub_board ) <EOL> target_sub_board_ids = [ <EOL> sb . get_id ( ) for sb in self . target_sub_boards ] <EOL> self . settings . set ( target_board_id , target_sub_board_ids ) <EOL> def change_target_board ( self , board_id ) : <EOL> self . settings . set ( '<STR_LIT>' , board_id ) <EOL> self . check_target_board ( ) <EOL> def change_target_sub_board ( self , option_index , sub_board_id ) : <EOL> if self . target_board and self . target_board . has_options ( ) : <EOL> target_board_id = self . target_board . get_id ( ) <EOL> target_sub_board_ids = self . settings . get ( target_board_id ) <EOL> target_sub_board_ids [ option_index ] = sub_board_id <EOL> self . settings . set ( target_board_id , target_sub_board_ids ) <EOL> self . check_target_sub_boards ( ) <EOL> def get_target_board ( self ) : <EOL> return self . target_board <EOL> def get_target_sub_boards ( self ) : <EOL> return self . target_sub_boards <EOL> def get_target_arch ( self ) : <EOL> target_board_id = self . target_board . get_id ( ) <EOL> ids = target_board_id . split ( '<STR_LIT:.>' ) <EOL> target_arch = ids [ - <NUM_LIT:2> ] <EOL> return target_arch <EOL> def get_params ( self ) : <EOL> params = { } <EOL> if self . target_board : <EOL> params . update ( self . target_board . get_params ( ) ) <EOL> for target_sub_board in self . target_sub_boards : <EOL> params . update ( target_sub_board . get_params ( ) ) <EOL> return params <EOL> class TargetSubBoardInfo ( object ) : <EOL> def __init__ ( self , target_board , option_index ) : <EOL> self . target_sub_board = None <EOL> self . target_board = target_board <EOL> self . option_index = option_index <EOL> self . settings = base . settings . get_arduino_settings ( ) <EOL> self . check_target_sub_board ( ) <EOL> def check_target_sub_board ( self ) : <EOL> if self . target_board : <EOL> target_board_id = self . target_board . get_id ( ) <EOL> target_sub_board_ids = self . settings . get ( target_board_id , [ ] ) <EOL> if self . option_index < len ( target_sub_board_ids ) : <EOL> target_sub_board_id = target_sub_board_ids [ self . option_index ] <EOL> options = self . target_board . get_options ( ) <EOL> option = options [ self . option_index ] <EOL> self . target_sub_board = option . get_item ( target_sub_board_id ) <EOL> if not self . target_sub_board : <EOL> options = self . target_board . get_options ( ) <EOL> option = options [ self . option_index ] <EOL> sub_boards = option . get_items ( ) <EOL> self . target_sub_board = sub_boards [ <NUM_LIT:0> ] <EOL> def get_target_sub_board ( self ) : <EOL> return self . target_sub_board <EOL> def get_params ( self ) : <EOL> return self . target_sub_board . get_params ( ) <EOL> def load_boards ( root_dirs ) : <EOL> boards = [ ] <EOL> for root_dir in root_dirs : <EOL> for package in root_dir . get_packages ( ) : <EOL> for platform in package . get_platforms ( ) : <EOL> boards += platform . get_boards ( ) <EOL> return boards </s>
