Clone of official tools
test_configs/__init__.py@47:21ae3e5a7128, 2021-02-04 (annotated)
- Committer:
- Anders Blomdell
- Date:
- Thu Feb 04 17:17:13 2021 +0100
- Revision:
- 47:21ae3e5a7128
- Parent:
- 43:2a7da56ebd24
Add a few normpath calls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
theotherjimmy |
43:2a7da56ebd24 | 1 | from os.path import dirname, abspath, join, exists |
theotherjimmy |
43:2a7da56ebd24 | 2 | |
theotherjimmy |
43:2a7da56ebd24 | 3 | from tools.utils import json_file_to_dict |
theotherjimmy |
43:2a7da56ebd24 | 4 | from tools.targets import TARGET_MAP |
theotherjimmy |
43:2a7da56ebd24 | 5 | from tools.config import Config |
theotherjimmy |
43:2a7da56ebd24 | 6 | |
theotherjimmy |
43:2a7da56ebd24 | 7 | CONFIG_DIR = dirname(abspath(__file__)) |
theotherjimmy |
43:2a7da56ebd24 | 8 | CONFIG_MAP = json_file_to_dict(join(CONFIG_DIR, "config_paths.json")) |
theotherjimmy |
43:2a7da56ebd24 | 9 | TARGET_CONFIGS = json_file_to_dict(join(CONFIG_DIR, "target_configs.json")) |
theotherjimmy |
43:2a7da56ebd24 | 10 | |
theotherjimmy |
43:2a7da56ebd24 | 11 | def get_valid_configs(target_name): |
theotherjimmy |
43:2a7da56ebd24 | 12 | if target_name in TARGET_CONFIGS: |
theotherjimmy |
43:2a7da56ebd24 | 13 | target_config = TARGET_CONFIGS[target_name] |
theotherjimmy |
43:2a7da56ebd24 | 14 | elif (target_name in TARGET_MAP and 'EMAC' in TARGET_MAP[target_name].device_has): |
theotherjimmy |
43:2a7da56ebd24 | 15 | target_config = { "default_test_configuration": "ETHERNET", "test_configurations": ["ETHERNET"] } |
theotherjimmy |
43:2a7da56ebd24 | 16 | else: |
theotherjimmy |
43:2a7da56ebd24 | 17 | return {} |
theotherjimmy |
43:2a7da56ebd24 | 18 | |
theotherjimmy |
43:2a7da56ebd24 | 19 | config_dict = {} |
theotherjimmy |
43:2a7da56ebd24 | 20 | for attr in CONFIG_MAP: |
theotherjimmy |
43:2a7da56ebd24 | 21 | if attr in target_config['test_configurations']: |
theotherjimmy |
43:2a7da56ebd24 | 22 | config_dict[attr] = CONFIG_MAP[attr] |
theotherjimmy |
43:2a7da56ebd24 | 23 | return config_dict |
theotherjimmy |
43:2a7da56ebd24 | 24 | |
theotherjimmy |
43:2a7da56ebd24 | 25 | def get_config_path(conf_name, target_name): |
theotherjimmy |
43:2a7da56ebd24 | 26 | configs = get_valid_configs(target_name) |
theotherjimmy |
43:2a7da56ebd24 | 27 | if configs and conf_name.upper() in configs: |
theotherjimmy |
43:2a7da56ebd24 | 28 | return join(CONFIG_DIR, configs[conf_name.upper()]) |
theotherjimmy |
43:2a7da56ebd24 | 29 | else: |
theotherjimmy |
43:2a7da56ebd24 | 30 | return None |
theotherjimmy |
43:2a7da56ebd24 | 31 | |
theotherjimmy |
43:2a7da56ebd24 | 32 | def get_default_config(source_dir, target_name): |
theotherjimmy |
43:2a7da56ebd24 | 33 | if target_name in TARGET_CONFIGS: |
theotherjimmy |
43:2a7da56ebd24 | 34 | config_name = TARGET_CONFIGS[target_name]['default_test_configuration'] |
theotherjimmy |
43:2a7da56ebd24 | 35 | if config_name == "NONE": |
theotherjimmy |
43:2a7da56ebd24 | 36 | return None |
theotherjimmy |
43:2a7da56ebd24 | 37 | return join(CONFIG_DIR, CONFIG_MAP[config_name]) |
theotherjimmy |
43:2a7da56ebd24 | 38 | elif Config.find_app_config(source_dir): |
theotherjimmy |
43:2a7da56ebd24 | 39 | return None |
theotherjimmy |
43:2a7da56ebd24 | 40 | elif (target_name in TARGET_MAP and 'EMAC' in TARGET_MAP[target_name].device_has): |
theotherjimmy |
43:2a7da56ebd24 | 41 | return join(CONFIG_DIR, CONFIG_MAP["ETHERNET"]) |
theotherjimmy |
43:2a7da56ebd24 | 42 | else: |
theotherjimmy |
43:2a7da56ebd24 | 43 | return None |