|
4 | 4 | import glob
|
5 | 5 | from common import CommonWebPageFuncs
|
6 | 6 |
|
7 |
| -#Initialise the common webpage functions (cw) which in turn initialises all relevant environment variables. |
| 7 | +# Get the logger from CommonWebPageFuncs |
8 | 8 | cw = CommonWebPageFuncs()
|
| 9 | +logger = cw.logger |
9 | 10 |
|
10 |
| -#Checksout validation webpage branch |
11 |
| -cw.checkout_validation_webpage_branch() |
| 11 | +try: |
| 12 | + # Checks out validation webpage branch |
| 13 | + cw.checkout_validation_webpage_branch() |
12 | 14 |
|
13 |
| -# More specific stuff here |
14 |
| -run_dir = os.path.join(cw.ValidationPath, "Webpage", cw.GIT_COMMIT) |
| 15 | + # More specific stuff here |
15 | 16 |
|
16 |
| -for job_dir in glob.glob(f"{run_dir}/[0-9]*/"): |
17 |
| - try: |
18 |
| - jobnum = int(job_dir.rsplit('/', 2)[-2]) |
19 |
| - except: |
20 |
| - #this happens if we have a directory that starts with a number, but has letters in it |
21 |
| - continue |
22 |
| - #If the job directory doesn't exist, die. |
23 |
| - if not os.path.isdir(job_dir): |
24 |
| - break # Changed from boolean as 'break' makes code easier to use imo. |
| 17 | + run_dir = os.path.join(cw.ValidationPath, "Webpage", cw.GIT_COMMIT) |
25 | 18 |
|
26 |
| - with open(os.path.join(job_dir, "index.html"), "r") as f: |
27 |
| - colour = f.readlines()[-1] |
| 19 | + # Check if the run directory exists |
| 20 | + if not os.path.isdir(run_dir): |
| 21 | + raise FileNotFoundError(f"Run directory '{run_dir}' does not exist") |
28 | 22 |
|
29 |
| - with open(os.path.join(run_dir, "index.html"), "r") as f: |
30 |
| - webpage_content = f.read() |
| 23 | + for job_dir in glob.glob(f"{run_dir}/[0-9]*/"): |
| 24 | + try: |
| 25 | + jobnum = int(job_dir.rsplit('/', 2)[-2]) |
| 26 | + except ValueError: |
| 27 | + # This happens if we have a directory that starts with a number but has letters in it |
| 28 | + continue |
31 | 29 |
|
32 |
| - jobnumpad = f"{jobnum:04d}" |
33 |
| - webpage_content = webpage_content.replace(f"'#00FFFF'COLOUR{jobnumpad}", colour) # Equivalent to the sed command used in the shell script. |
| 30 | + # If the job directory doesn't exist, skip it |
| 31 | + if not os.path.isdir(job_dir): |
| 32 | + continue |
34 | 33 |
|
35 |
| - #Put it all together. |
36 |
| - with open(os.path.join(run_dir, "index.html"), "w") as f: |
37 |
| - f.write(webpage_content) |
| 34 | + with open(os.path.join(job_dir, "index.html"), "r") as f: |
| 35 | + colour = f.readlines()[-1] |
38 | 36 |
|
| 37 | + with open(os.path.join(run_dir, "index.html"), "r") as f: |
| 38 | + webpage_content = f.read() |
39 | 39 |
|
40 |
| -cw.update_webpage() |
| 40 | + jobnumpad = f"{jobnum:04d}" |
| 41 | + webpage_content = webpage_content.replace(f"'#00FFFF'COLOUR{jobnumpad}", colour) # Equivalent to the sed command used in the shell script. |
| 42 | + |
| 43 | + # Put it all together. |
| 44 | + with open(os.path.join(run_dir, "index.html"), "w") as f: |
| 45 | + f.write(webpage_content) |
| 46 | + |
| 47 | + cw.update_webpage() |
| 48 | + |
| 49 | +except FileNotFoundError as e: |
| 50 | + logger.error(f"An unexpected FileNotFoundError occured: {e}") |
| 51 | +except Exception as e: |
| 52 | + logger.error(f"An unexpected error occurred: {e}") |
0 commit comments