Marco Mayer / Mbed OS Queue
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers __init__.py Source File

__init__.py

00001 from os.path import dirname, abspath, join
00002 
00003 from tools.utils import json_file_to_dict
00004 from tools.targets import TARGET_MAP
00005 
00006 CONFIG_DIR = dirname(abspath(__file__))
00007 CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json"))
00008 TARGET_CONFIGS = json_file_to_dict(join(CONFIG_DIR, "target_configs.json"))
00009 
00010 def get_valid_configs(target_name):
00011     if target_name in TARGET_CONFIGS:
00012         target_config = TARGET_CONFIGS[target_name]
00013     elif (target_name in TARGET_MAP and 'LWIP' in TARGET_MAP[target_name].features):
00014         target_config = { "default_test_configuration": "ETHERNET", "test_configurations": ["ETHERNET"] }
00015     else:
00016         return {}
00017 
00018     config_dict = {}
00019     for attr in CONFIG_MAP:
00020         if attr in target_config['test_configurations']:
00021             config_dict[attr] = CONFIG_MAP[attr]
00022     return config_dict
00023 
00024 def get_config_path(conf_name, target_name):
00025     configs = get_valid_configs(target_name)
00026     if configs and conf_name.upper() in configs:
00027         return join(CONFIG_DIR, configs[conf_name.upper()])
00028     else:
00029         return None
00030 
00031 def get_default_config(target_name):
00032     if target_name in TARGET_CONFIGS:
00033         config_name = TARGET_CONFIGS[target_name]['default_test_configuration']
00034         if config_name == "NONE":
00035             return None
00036         return join(CONFIG_DIR, CONFIG_MAP[config_name])
00037     elif (target_name in TARGET_MAP and 'LWIP' in TARGET_MAP[target_name].features):
00038         return join(CONFIG_DIR, CONFIG_MAP["ETHERNET"])
00039     else:
00040         return None