Skip to content

Commit

Permalink
Merge pull request #698 from lbarraga/timestamp-available-software
Browse files Browse the repository at this point in the history
Timestamp variable in available software script
boegel authored Sep 10, 2024
2 parents afee5e8 + 6b21da5 commit 53d76bb
Showing 2 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions mkdocs/extra/gent.yml
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ hpcname: hpcugent
loginnode: login.hpc.ugent.be
loginhost: gligar07.gastly.os
altloginhost: gligar08.gastly.os
modules_last_updated: Mon, 09 Sep 2024 at 14:06:35 CEST # This line is automatically updated by scripts/available_modules/available_modules.py
# get these with ssh-keyscan gligar01.ugent.be > file
# ssh-keygen -l -f file
# ssh-keygen -l -f file -E md5
42 changes: 36 additions & 6 deletions scripts/available_software/available_software.py
Original file line number Diff line number Diff line change
@@ -77,7 +77,9 @@ def main():
json_path = generate_json_detailed(modules, path_data_dir)
print("Done!")
print("Generate detailed pages... ", end="", flush=True)
generate_detail_pages(json_path, os.path.join(root_dir, "mkdocs/docs/HPC/only/gent/available_software/detail"))
detail_folder = os.path.join(root_dir, "mkdocs/docs/HPC/only/gent/available_software/detail")
generated_time_yml = os.path.join(root_dir, "mkdocs/extra/gent.yml") # yml containing time the data was generated
generate_detail_pages(json_path, detail_folder, generated_time_yml)
print("Done!")


@@ -356,7 +358,6 @@ def generate_software_table_data(software_data: dict, clusters: list) -> list:
def generate_software_detail_page(
software_name: str,
software_data: dict,
generated_time: str,
clusters: list,
path: str
) -> None:
@@ -365,7 +366,6 @@ def generate_software_detail_page(
@param software_name: Name of the software
@param software_data: Additional information about the software (version, etc...)
@param generated_time: Timestamp when the data was generated
@param clusters: List with all the cluster names
@param path: Path of the directory where the detailed page will be created.
"""
@@ -381,7 +381,7 @@ def generate_software_detail_page(
md_file.new_paragraph(f"To start using {software_name}, load one of these modules using a `module load` command "
f"like:")
md_file.insert_code(f"module load {newest_version}", language="shell")
md_file.new_paragraph(f"(This data was automatically generated on {generated_time})", bold_italics_code="i")
md_file.new_paragraph("(This data was automatically generated on {{modules_last_updated}})", bold_italics_code="i")
md_file.new_line()

md_file.new_table(
@@ -399,17 +399,47 @@ def generate_software_detail_page(
f.write("---\nhide:\n - toc\n---\n" + read_data)


def generate_detail_pages(json_path, dest_path) -> None:
def generate_detail_pages(json_path, dest_path, generated_time_yml) -> None:
"""
Generate all the detailed pages for all the software that is available.
"""

with open(json_path) as json_data:
data = json.load(json_data)

# update the time the data was generated
update_generated_time_yml(generated_time_yml, data["time_generated"])

all_clusters = data["clusters"]
for software, content in data["software"].items():
generate_software_detail_page(software, content, data["time_generated"], all_clusters, dest_path)
generate_software_detail_page(software, content, all_clusters, dest_path)


def update_generated_time_yml(generated_time_yml, generated_time) -> None:
"""
Update the time the data was generated in the YAML file.
This is done by updating the field 'modules_last_updated'.
@param generated_time_yml: Path to the YAML file containing the field 'modules_last_updated'
@param generated_time: Time the data was generated
"""
key = "modules_last_updated"

# Read the file and replace the specific line
with open(generated_time_yml, 'r') as file:
lines = file.readlines()

replaced = False
with open(generated_time_yml, 'w') as file:
for line in lines:
if line.startswith(key):
comment = "# This line is automatically updated by scripts/available_modules/available_modules.py"
line = f"{key}: {generated_time} {comment}\n"
replaced = True
file.write(line)

if not replaced:
print(f"WARNING: Could not find the key '{key}' in the YAML file '{generated_time_yml}'")


# --------------------------------------------------------------------------------------------------------

0 comments on commit 53d76bb

Please sign in to comment.