| 1 |
# mypy: allow-untyped-defs |
| 2 |
|
| 3 |
import json |
| 4 |
import os |
| 5 |
|
| 6 |
from tools.wpt import wpt |
| 7 |
|
| 8 |
DEFAULT_CONFIGURATION_FILE_PATH = os.path.join(wpt.localpaths.repo_root, "./tools/wave/config.default.json") |
| 9 |
|
| 10 |
|
| 11 |
def load(configuration_file_path): |
| 12 |
configuration = {} |
| 13 |
if configuration_file_path: |
| 14 |
configuration = load_configuration_file(configuration_file_path) |
| 15 |
default_configuration = load_configuration_file( |
| 16 |
DEFAULT_CONFIGURATION_FILE_PATH) |
| 17 |
|
| 18 |
configuration["wpt_port"] = configuration.get( |
| 19 |
"ports", default_configuration["ports"]).get( |
| 20 |
"http", default_configuration["ports"]["http"])[0] |
| 21 |
configuration["wpt_ssl_port"] = configuration.get( |
| 22 |
"ports", default_configuration["ports"]).get( |
| 23 |
"https", default_configuration["ports"]["https"])[0] |
| 24 |
|
| 25 |
web_root = configuration.get( |
| 26 |
"wave", default_configuration["wave"]).get( |
| 27 |
"web_root", default_configuration["wave"]["web_root"]) |
| 28 |
if not web_root.startswith("/"): |
| 29 |
web_root = "/" + web_root |
| 30 |
if not web_root.endswith("/"): |
| 31 |
web_root += "/" |
| 32 |
configuration["web_root"] = web_root |
| 33 |
|
| 34 |
configuration["results_directory_path"] = configuration.get( |
| 35 |
"wave", default_configuration["wave"]).get( |
| 36 |
"results", default_configuration["wave"]["results"]) |
| 37 |
|
| 38 |
configuration["timeouts"] = {} |
| 39 |
configuration["timeouts"]["automatic"] = configuration.get( |
| 40 |
"wave", default_configuration["wave"]).get( |
| 41 |
"timeouts", default_configuration["wave"]["timeouts"]).get( |
| 42 |
"automatic", default_configuration["wave"]["timeouts"]["automatic"]) |
| 43 |
configuration["timeouts"]["manual"] = configuration.get( |
| 44 |
"wave", default_configuration["wave"]).get( |
| 45 |
"timeouts", default_configuration["wave"]["timeouts"]).get( |
| 46 |
"manual", default_configuration["wave"]["timeouts"]["manual"]) |
| 47 |
|
| 48 |
configuration["hostname"] = configuration.get( |
| 49 |
"browser_host", default_configuration["browser_host"]) |
| 50 |
|
| 51 |
configuration["import_results_enabled"] = configuration.get( |
| 52 |
"wave", default_configuration["wave"]).get( |
| 53 |
"enable_import_results", |
| 54 |
default_configuration["wave"]["enable_import_results"]) |
| 55 |
|
| 56 |
configuration["read_sessions_enabled"] = configuration.get( |
| 57 |
"wave", default_configuration["wave"]).get( |
| 58 |
"enable_read_sessions", |
| 59 |
default_configuration["wave"]["enable_read_sessions"]) |
| 60 |
|
| 61 |
configuration["persisting_interval"] = configuration.get( |
| 62 |
"wave", default_configuration["wave"]).get( |
| 63 |
"persisting_interval", default_configuration["wave"]["persisting_interval"]) |
| 64 |
|
| 65 |
configuration["event_cache_duration"] = configuration.get( |
| 66 |
"wave", default_configuration["wave"]).get( |
| 67 |
"event_cache_duration", default_configuration["wave"]["event_cache_duration"]) |
| 68 |
|
| 69 |
configuration["tests_directory_path"] = os.getcwd() |
| 70 |
|
| 71 |
configuration["manifest_file_path"] = os.path.join( |
| 72 |
os.getcwd(), "MANIFEST.json") |
| 73 |
|
| 74 |
configuration["api_titles"] = configuration.get( |
| 75 |
"wave", default_configuration["wave"]).get( |
| 76 |
"api_titles", default_configuration["wave"]["api_titles"]) |
| 77 |
|
| 78 |
configuration["enable_test_type_selection"] = configuration.get( |
| 79 |
"wave", default_configuration["wave"]).get( |
| 80 |
"enable_test_type_selection", default_configuration["wave"]["enable_test_type_selection"]) |
| 81 |
|
| 82 |
configuration["enable_test_file_selection"] = configuration.get( |
| 83 |
"wave", default_configuration["wave"]).get( |
| 84 |
"enable_test_file_selection", default_configuration["wave"]["enable_test_file_selection"]) |
| 85 |
|
| 86 |
return configuration |
| 87 |
|
| 88 |
|
| 89 |
def load_configuration_file(path): |
| 90 |
if not os.path.isfile(path): |
| 91 |
return {} |
| 92 |
|
| 93 |
configuration = None |
| 94 |
with open(path) as configuration_file: |
| 95 |
configuration_file_content = configuration_file.read() |
| 96 |
configuration = json.loads(configuration_file_content) |
| 97 |
return configuration |