Skip to content

Commit 581c377

Browse files
committed
add_no_cache_param
1 parent 0d73576 commit 581c377

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed
Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,78 @@
1-
import os
21
import json
3-
2+
import os
3+
import random
4+
import sys
45

56
output_folders = [
6-
"source-output", # dev output
7+
"source-output", # dev output
78
"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
910
]
1011

1112

12-
def read_json_file(filename):
13+
def _read_json_file(filename):
1314
dirname = os.path.dirname(__file__)
1415
meta_filename = os.path.join(dirname, filename)
15-
with open(meta_filename, "r") as file:
16+
with open(meta_filename) as file:
1617
metadata = json.load(file)
1718
return metadata["applications"]
1819

1920

2021
def update_apps_metadata():
2122
dirname = os.path.dirname(__file__)
22-
applications = read_json_file("apps_metadata.json")
23+
applications = _read_json_file("apps_metadata.json")
2324
for i in applications:
2425
application = i.get("application")
26+
replacements = i.get("replacements")
2527
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+
)
2731
if not os.path.isfile(filename):
2832
continue
29-
with open(filename, "r") as file:
33+
with open(filename) as file:
3034
data = file.read()
31-
replacements = i.get("replacements")
3235
for key in replacements:
3336
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:
3639
print(f"Updating app metadata: {filename}")
3740
file.write(data)
3841

3942

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+
4073
if __name__ == "__main__":
4174
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)

services/static-webserver/client/source/boot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</head>
6868
<body>
6969
${preBootJs}
70-
<script type="text/javascript" src="${appPath}boot.js"></script>
70+
<script type="text/javascript" src="${appPath}boot.js&osparc_client_version=vcs_ref_client"></script>
7171
</body>
7272
<script>
7373
window.markerConfig = {

0 commit comments

Comments
 (0)