From 27b2730f73e0a18c174bfebc8d2871a6a039f842 Mon Sep 17 00:00:00 2001
From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de>
Date: Thu, 8 Jun 2023 17:10:21 +0200
Subject: [PATCH] first attempt at status command

---
 mpsd-software-environment.py | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/mpsd-software-environment.py b/mpsd-software-environment.py
index dc2acb1..f112f6a 100755
--- a/mpsd-software-environment.py
+++ b/mpsd-software-environment.py
@@ -12,6 +12,7 @@ import time
 from pathlib import Path
 from typing import List, Tuple, Union
 import re
+import json
 
 # If 'rich' is available ("pip install rich" or "apt-get install python3-rich"),
 # then use coloured output, otherwise proceed as before
@@ -834,16 +835,30 @@ def environment_status(mpsd_release, script_dir):
     # raise NotImplementedError(msg)
     release_base_dir = script_dir / mpsd_release
     os.environ.get("MPSD_OS", "UNKNOWN_OS")
-    microarch = get_native_microarchitecture()
-    toolchain_dir = release_base_dir / microarch
+    sys_microarch = get_native_microarchitecture()
+    toolchain_dir = release_base_dir / sys_microarch
     spack_dir = toolchain_dir / "spack"
+    lmod_toolchain_dir = release_base_dir / sys_microarch / "lmod" / "Core" / "toolchains"
+
     if not spack_dir.exists():
         raise ValueError(
             f"Release {mpsd_release} has not been completly installed yet"
             ", try reinstalling it (spack directory not found)"
         )
-    with os_chdir(spack_dir):
-        pass
+    # find all folders for all microarch in the release directory except for the blacklisted folder
+    black_listed_microarchs = ["spack-environments", "logs"]
+
+    list_of_microarchs = os.listdir(release_base_dir) 
+    list_of_microarchs.remove(black_listed_microarchs)
+    toolchain_map = {}
+    for microarch in list_of_microarchs:
+        # get a list of all the toolchains in the microarch
+        possible_toolchains = (release_base_dir/microarch).glob("lmod/Core/toolchains/*.lua")
+        # append toolchain which is the name of the file without the .lua extension
+        toolchain_map[microarch] = [toolchain.stem for toolchain in possible_toolchains]
+
+    # pretty print the toolchain map
+    print(json.dumps(toolchain_map, indent=4, sort_keys=True))
 
 
 def main():
-- 
GitLab