|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 | import random |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | output_folders = [ |
6 | 7 | "source-output", # dev output |
@@ -40,40 +41,38 @@ def update_apps_metadata(): |
40 | 41 |
|
41 | 42 |
|
42 | 43 | def _get_output_file_paths(filename): |
43 | | - index_file_paths = [] |
| 44 | + output_file_paths: list[Path] = [] |
44 | 45 | dirname = os.path.dirname(__file__) |
45 | 46 | applications = _read_json_file("apps_metadata.json") |
46 | 47 | for i in applications: |
47 | 48 | application = i.get("application") |
48 | 49 | for output_folder in output_folders: |
49 | | - index_file_paths.append( |
50 | | - os.path.join(dirname, "..", output_folder, application, filename) |
51 | | - ) |
52 | | - return index_file_paths |
| 50 | + result = Path(dirname).joinpath("..", output_folder, application, filename) |
| 51 | + if result.is_file(): |
| 52 | + output_file_paths.append(result.resolve()) |
| 53 | + return output_file_paths |
53 | 54 |
|
54 | 55 |
|
55 | 56 | def add_no_cache_param(vcs_ref_client): |
56 | 57 | index_file_paths = _get_output_file_paths("index.html") |
57 | 58 | for index_file_path in index_file_paths: |
58 | | - if not os.path.isfile(index_file_path): |
59 | | - continue |
60 | | - with open(index_file_path) as index_file: |
61 | | - data = index_file.read() |
62 | | - data = data.replace("${boot_params}", "nocache=" + vcs_ref_client) |
63 | | - with open(index_file_path, "w") as file: |
64 | | - print(f"Updating vcs_ref_client: {index_file_path}") |
65 | | - file.write(data) |
| 59 | + print(f"Updating vcs_ref_client: {index_file_path}") |
| 60 | + index_file_path.write_text( |
| 61 | + index_file_path.read_text().replace( |
| 62 | + "${boot_params}", |
| 63 | + "nocache=" + vcs_ref_client, |
| 64 | + ) |
| 65 | + ) |
66 | 66 |
|
67 | 67 | boot_file_paths = _get_output_file_paths("boot.js") |
68 | 68 | for boot_file_path in boot_file_paths: |
69 | | - if not os.path.isfile(boot_file_path): |
70 | | - continue |
71 | | - with open(boot_file_path) as boot_file: |
72 | | - data = boot_file.read() |
73 | | - data = data.replace("addNoCacheParam : false", "addNoCacheParam : true") |
74 | | - with open(boot_file_path, "w") as file: |
75 | | - print(f"Updating URL_PARAMETERS: {boot_file_path}") |
76 | | - file.write(data) |
| 69 | + print(f"Updating addNoCacheParam URL_PARAMETERS: {boot_file_path}") |
| 70 | + boot_file_path.write_text( |
| 71 | + boot_file_path.read_text().replace( |
| 72 | + "addNoCacheParam : false", |
| 73 | + "addNoCacheParam : true", |
| 74 | + ) |
| 75 | + ) |
77 | 76 |
|
78 | 77 |
|
79 | 78 | if __name__ == "__main__": |
|
0 commit comments