Skip to content

Commit

Permalink
cleanup code + comments + change file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
milachae committed Aug 25, 2023
1 parent c92dfe4 commit 578ea83
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 70 deletions.
4 changes: 3 additions & 1 deletion config/templates/hpc.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ docs_dir: docs/HPC

nav:
- Welcome: index.md
- Overview modules: module_overview.md
{%- if site == 'Gent' %}
- Overview modules: only/gent/module_overview/index.md
{%- endif %}
- Introduction to HPC: introduction.md
- Getting an HPC Account: account.md
- Connecting to the HPC infrastructure: connecting.md
Expand Down
1 change: 0 additions & 1 deletion mkdocs/docs/HPC/data/json_data.json

This file was deleted.

48 changes: 2 additions & 46 deletions mkdocs/docs/HPC/javascripts/populate_overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,6 @@
* @author: Michiel Lachaert
*/

/**
* A function that populates the table on the module overview page with information about all the available modules.
*/
// function populate_overview_new() {
// fetch("../data/modulemap.json")
// .then((response) => response.json())
// .then((json) => {
// // CONSTRUCT TABLE
//
// const all_clusters = Object.entries(json.clusters)
// .filter(([, value]) => !value.includes("."))
// .map(x => {
// return {"title": x[0], "className": 'dt-center'}
// })
//
// const table = new DataTable('#overview_table', {
// columns: [...[{"title": "name"}], ...all_clusters],
// paging: false,
// });
//
//
// // ADD DATA
// let new_rows = [];
//
// // list_avaible contains a list with booleans.
// // These booleans indicates if the software is available on the corresponding cluster.
// for (const [software, versions] of Object.entries(json.software)) {
// let new_row = [
// `<a href="../detail/${software}_detail">${software}</a>`
// ]
//
// const available = Object.keys(versions[".default"])
// all_clusters
// .forEach(cluster =>
// new_row.push(available.includes(cluster.title) ? "x" : "-")
// )
//
// new_rows.push(new_row);
// }
//
// table.rows.add(new_rows).draw();
// })
// }

/**
* A function that populates the table on the module overview page with information about all the available modules.
*/
Expand All @@ -95,7 +51,7 @@ function populate_overview(json_data) {
// list_avaible contains a list with booleans.
// These booleans indicates if the software is available on the corresponding cluster.
for (const [software, list_available] of Object.entries(json.modules)) {
let new_row = [`<a href="../detail/${software}_detail">${software}</a>`];
let new_row = [`<a href="detail/${software}">${software}</a>`];
list_available.forEach(bool => new_row.push(bool ? "x" : "-"));
new_rows.push(new_row);
}
Expand All @@ -107,6 +63,6 @@ function populate_overview(json_data) {
// Only start populating the table if the correct page has been loaded.
document$.subscribe(function() {
if (document.getElementById("overview_table")) {
populate_overview("../data/json_data.json")
populate_overview("../module_overview/data/json_data.json")
}
})

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Empty file.
File renamed without changes.
41 changes: 30 additions & 11 deletions scripts/module_overview/module_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,42 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
Python script to generate a detail page for the avalable modules across different clusters, in MarkDown format.
Python script to generate a detail page for the available modules across different clusters, in MarkDown format.
It generates 1 markdown for each module.
@author: Michiel Lachaert (Ghent University)
"""

import argparse
import json
from mdutils import MdUtils
from natsort import natsorted
import os


def main():
parser = argparse.ArgumentParser(description="Get args.")
parser.add_argument(
"--json",
"-j",
dest="json",
help="Path to the JSON.",
required=True
)
parser.add_argument(
"--path",
"-p",
dest="path",
help="Path to the directory where the detail folder will be placed.",
required=True
)

args = parser.parse_args()
generate_detail_pages(args.json, args.path)


def dict_sort(dictionary: dict) -> dict:
"""
Sort a dictionary by key
Sort a dictionary by key.
@param dictionary: A dictionary
@return: Sorted dictionary
Expand All @@ -56,7 +77,7 @@ def generate_software_table_data(software_data: dict, clusters: list) -> list:
"""
table_data = [" "] + clusters

for k, v in software_data.items():
for k, v in list(software_data.items())[::-1]:
row = [k]

for cluster in clusters:
Expand All @@ -75,7 +96,7 @@ def generate_software_detail_page(software_name: str, software_data: dict, clust
@param clusters: List with all the cluster names
@param path: Path of the directory where the detailed page will be created.
"""
filename = f"{path}/{software_name}_detail.md"
filename = f"{path}/{software_name}.md"
md_file = MdUtils(file_name=filename, title=f"detailed overview of {software_name}")

sorted_versions = dict_sort(software_data["versions"])
Expand All @@ -94,20 +115,18 @@ def generate_software_detail_page(software_name: str, software_data: dict, clust
f.write("---\nhide:\n - toc\n---\n" + read_data)


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

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

path = "/home/milachae/Documents/HPC_Vakantiejob_2023/vsc_user_docs/mkdocs/docs/HPC/detail"
os.makedirs(path, exist_ok=True)
all_clusters = data["clusters"]
for software, content in data["software"].items():
generate_software_detail_page(software, content, all_clusters, path)
generate_software_detail_page(software, content, all_clusters, dest_path)


if __name__ == '__main__':
generate_detail_pages()
main()
22 changes: 11 additions & 11 deletions scripts/module_overview/module_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
from typing import Union, Tuple


# --------------------------------------------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------------------------------------------

def main():
# Generate the JSON overviews
modules = modules_ugent()
generate_json_overview(modules)
generate_json_detailed(modules)


# --------------------------------------------------------------------------------------------------------
# Functions to run "module" commands
# --------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -357,16 +368,5 @@ def generate_json_detailed(modules: dict) -> None:
json.dump(json_data, outfile)


# --------------------------------------------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------------------------------------------

def main():
# Generate the JSON overviews
modules = modules_ugent()
generate_json_overview(modules)
generate_json_detailed(modules)


if __name__ == '__main__':
main()

0 comments on commit 578ea83

Please sign in to comment.