-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFinaliseWebpages.py
55 lines (41 loc) · 1.69 KB
/
FinaliseWebpages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
import os
import glob
import sys
from common import CommonWebPageFuncs
# Get the logger from CommonWebPageFuncs
cw = CommonWebPageFuncs()
logger = cw.logger
try:
# Checks out validation webpage branch
cw.checkout_validation_webpage_branch()
# More specific stuff here
run_dir = os.path.join(cw.ValidationPath, "Webpage", cw.GIT_COMMIT)
# Check if the run directory exists
if not os.path.isdir(run_dir):
raise FileNotFoundError(f"Run directory '{run_dir}' does not exist")
for job_dir in glob.glob(f"{run_dir}/[0-9]*/"):
try:
jobnum = int(job_dir.rsplit('/', 2)[-2])
except ValueError:
# This happens if we have a directory that starts with a number but has letters in it
continue
# If the job directory doesn't exist, skip it
if not os.path.isdir(job_dir):
continue
with open(os.path.join(job_dir, "index.html"), "r") as f:
colour = f.readlines()[-1]
with open(os.path.join(run_dir, "index.html"), "r") as f:
webpage_content = f.read()
jobnumpad = f"{jobnum:04d}"
webpage_content = webpage_content.replace(f"'#00FFFF'COLOUR{jobnumpad}", colour) # Equivalent to the sed command used in the shell script.
# Put it all together.
with open(os.path.join(run_dir, "index.html"), "w") as f:
f.write(webpage_content)
cw.update_webpage()
except FileNotFoundError as e:
logger.error(f"An unexpected FileNotFoundError occured: {e}")
sys.exit(1)
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")
sys.exit(1)