|
1 | | -import os |
2 | 1 | import json |
3 | | - |
| 2 | +import os |
| 3 | +import random |
| 4 | +import sys |
4 | 5 |
|
5 | 6 | output_folders = [ |
6 | | - "source-output", # dev output |
| 7 | + "source-output", # dev output |
7 | 8 | "build-output", # default production output |
8 | | - "build-client" # I believe we create the production outputs here |
| 9 | + "build-client", # I believe we create the production outputs here |
9 | 10 | ] |
10 | 11 |
|
11 | 12 |
|
12 | | -def read_json_file(filename): |
| 13 | +def _read_json_file(filename): |
13 | 14 | dirname = os.path.dirname(__file__) |
14 | 15 | meta_filename = os.path.join(dirname, filename) |
15 | | - with open(meta_filename, "r") as file: |
| 16 | + with open(meta_filename) as file: |
16 | 17 | metadata = json.load(file) |
17 | 18 | return metadata["applications"] |
18 | 19 |
|
19 | 20 |
|
20 | 21 | def update_apps_metadata(): |
21 | 22 | dirname = os.path.dirname(__file__) |
22 | | - applications = read_json_file("apps_metadata.json") |
| 23 | + applications = _read_json_file("apps_metadata.json") |
23 | 24 | for i in applications: |
24 | 25 | application = i.get("application") |
| 26 | + replacements = i.get("replacements") |
25 | 27 | for output_folder in output_folders: |
26 | | - filename = os.path.join(dirname, '..', output_folder, application, "index.html") |
| 28 | + filename = os.path.join( |
| 29 | + dirname, "..", output_folder, application, "index.html" |
| 30 | + ) |
27 | 31 | if not os.path.isfile(filename): |
28 | 32 | continue |
29 | | - with open(filename, "r") as file: |
| 33 | + with open(filename) as file: |
30 | 34 | data = file.read() |
31 | | - replacements = i.get("replacements") |
32 | 35 | for key in replacements: |
33 | 36 | replace_text = replacements[key] |
34 | | - data = data.replace("${"+key+"}", replace_text) |
35 | | - with open(filename, "w") as file: |
| 37 | + data = data.replace("${" + key + "}", replace_text) |
| 38 | + with open(filename, "w") as file: |
36 | 39 | print(f"Updating app metadata: {filename}") |
37 | 40 | file.write(data) |
38 | 41 |
|
39 | 42 |
|
| 43 | +def _get_index_file_paths(): |
| 44 | + index_file_paths = [] |
| 45 | + dirname = os.path.dirname(__file__) |
| 46 | + applications = _read_json_file("apps_metadata.json") |
| 47 | + for i in applications: |
| 48 | + application = i.get("application") |
| 49 | + for output_folder in output_folders: |
| 50 | + index_file_paths.append( |
| 51 | + os.path.join(dirname, "..", output_folder, application, "index.html") |
| 52 | + ) |
| 53 | + return index_file_paths |
| 54 | + |
| 55 | + |
| 56 | +def add_no_cache_param(vcs_ref_client): |
| 57 | + index_file_paths = _get_index_file_paths() |
| 58 | + for index_file_path in index_file_paths: |
| 59 | + if not os.path.isfile(index_file_path): |
| 60 | + continue |
| 61 | + with open(index_file_path) as index_file: |
| 62 | + data = index_file.read() |
| 63 | + if vcs_ref_client: |
| 64 | + data = data.replace("vcs_ref_client", vcs_ref_client) |
| 65 | + else: |
| 66 | + random.seed(5) |
| 67 | + data = data.replace("vcs_ref_client", str(random.random())) |
| 68 | + with open(index_file_path, "w") as file: |
| 69 | + print(f"Updating vcs_ref_client: {index_file_path}") |
| 70 | + file.write(data) |
| 71 | + |
| 72 | + |
40 | 73 | if __name__ == "__main__": |
41 | 74 | update_apps_metadata() |
| 75 | + vcs_ref_client = None |
| 76 | + if len(sys.argv) > 1: |
| 77 | + vcs_ref_client = sys.argv[1] |
| 78 | + add_no_cache_param(vcs_ref_client) |
0 commit comments