Skip to content
Snippets Groups Projects

Restructure log location

Merged Ashwin Kumar Karnad requested to merge restructure-log-location into main
Compare and
3 files
+ 92
17
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 69
14
@@ -10,7 +10,8 @@ import subprocess
@@ -10,7 +10,8 @@ import subprocess
import sys
import sys
import time
import time
from pathlib import Path
from pathlib import Path
from typing import List, Tuple
from typing import List, Tuple, Union
 
import re
# If 'rich' is available ("pip install rich" or "apt-get install python3-rich"),
# If 'rich' is available ("pip install rich" or "apt-get install python3-rich"),
# then use coloured output, otherwise proceed as before
# then use coloured output, otherwise proceed as before
@@ -30,18 +31,68 @@ for given system architecture and MPSD software stack version.\n
@@ -30,18 +31,68 @@ for given system architecture and MPSD software stack version.\n
The toolchains
The toolchains
are built using the bash script spack_setup.sh, and the results are logged. """
are built using the bash script spack_setup.sh, and the results are logged. """
 
call_date_iso = datetime.datetime.now().replace(microsecond=0).isoformat()
config_vars = {
config_vars = {
 
# kept inside the mpsd_release folder
"cmd_log_file": "install.log",
"cmd_log_file": "install.log",
"build_log_file": (
# Placeholder installer log file name, placed at mpsd_microarch/logs
"logs/mpsd_spack_ver_toolchains_"
"installer_log_file": f"mpsdrelease_microarch_{call_date_iso}_cmd.log",
f"{datetime.datetime.now().replace(microsecond=0).isoformat()}.log"
# Placeholder build log file name, placed at mpsd_microarch/logs
),
"build_log_file": f"mpsdrelease_microarch_{call_date_iso}_specifictoolchain_install.log",
# TODO: modify toolchains,mpsd_spack_ver when the variable is available
"metadata_tag_open": "!<meta>",
 
"metadata_tag_close": "</meta>!",
"spack_environments_repo": "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git",
"spack_environments_repo": "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git",
}
}
def set_up_logging(loglevel="warning", filename=None):
def log_metadata(key: str, value: str) -> None:
 
"""Log metadata to the log file.
 
 
This function logs metadata to the log file. The metadata is
 
enclosed in a tag, so that it can be easily found in the log file.
 
logging module is used to write the metadata to the log file.
 
 
Parameters
 
----------
 
key : str
 
key of the metadata
 
value : str
 
value of the metadata
 
returns : None
 
"""
 
logging.info(
 
f"{config_vars['metadata_tag_open']}{key}:{value}{config_vars['metadata_tag_close']}"
 
)
 
 
 
def read_metadata_from_logfile(logfile: Union[str, Path]) -> dict:
 
"""Read metadata from the log file.
 
 
This function reads metadata from the log file. The metadata is
 
enclosed in a tag, so that it can be easily found in the log file.
 
 
Parameters
 
----------
 
logfile : str or Path
 
log file name
 
returns : dict
 
dictionary containing the metadata
 
"""
 
with open(logfile, "r") as f:
 
log_text = f.read()
 
# check for all data that matches the regex
 
# metadata_tag_open {key}:{value} metadata_tag_close
 
# and return a dictionary with all the matches
 
return {
 
match.group(1): match.group(2)
 
for match in re.finditer(
 
f"{config_vars['metadata_tag_open']}(\w+):(\w+){config_vars['metadata_tag_close']}",
 
log_text,
 
)
 
}
 
 
 
def set_up_logging(loglevel="warning", filename="gol.log"):
"""Set up logging.
"""Set up logging.
This function sets up the logging configuration for the script.
This function sets up the logging configuration for the script.
@@ -466,8 +517,7 @@ def install_environment(
@@ -466,8 +517,7 @@ def install_environment(
# Set required variables
# Set required variables
release_base_dir = script_dir / mpsd_release
release_base_dir = script_dir / mpsd_release
os.environ.get("MPSD_OS", "UNKNOWN_OS")
mpsd_microarch = os.environ.get("MPSD_MICROARCH", "UNKNOWN_MICROARCH")
toolchain_dir = release_base_dir / mpsd_microarch
toolchain_dir = release_base_dir / mpsd_microarch
toolchain_dir.mkdir(parents=True, exist_ok=True)
toolchain_dir.mkdir(parents=True, exist_ok=True)
spack_setup_script = release_base_dir / "spack-environments" / "spack_setup.sh"
spack_setup_script = release_base_dir / "spack-environments" / "spack_setup.sh"
@@ -507,11 +557,7 @@ def install_environment(
@@ -507,11 +557,7 @@ def install_environment(
# _mpsd_spack_ver_ with mpsd_release
# _mpsd_spack_ver_ with mpsd_release
logging.info(f"Installing toolchain {toolchain} to {toolchain_dir}")
logging.info(f"Installing toolchain {toolchain} to {toolchain_dir}")
install_log_file = (
config_vars["build_log_file"]
.replace("mpsd_spack_ver_", f"{mpsd_release}_")
.replace("_toolchains_", f"_{toolchain}_")
)
# log the command
# log the command
setup_log_cmd(
setup_log_cmd(
mpsd_release,
mpsd_release,
@@ -629,7 +675,16 @@ def main():
@@ -629,7 +675,16 @@ def main():
# Carry out the action
# Carry out the action
args = parser.parse_args()
args = parser.parse_args()
 
# Get machine configs
 
os.environ.get("MPSD_OS", "UNKNOWN_OS")
 
os.environ.get("MPSD_MICROARCH", "UNKNOWN_MICROARCH")
# parse logging first
# parse logging first
 
# decide the log_file_name
 
(
 
config_vars["build_log_file"]
 
.replace("mpsd_spack_ver_", f"{mpsd_release}_")
 
.replace("_toolchains_", f"_{toolchain}_")
 
)
set_up_logging(args.loglevel)
set_up_logging(args.loglevel)
# target dir is the place where this script exists. the
# target dir is the place where this script exists. the
Loading