Skip to content
Snippets Groups Projects

Restructure log location

Merged Ashwin Kumar Karnad requested to merge restructure-log-location into main
Compare and
2 files
+ 120
11
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 75
11
@@ -12,6 +12,7 @@ import time
from pathlib import Path
from typing import List, Tuple, Union
import re
from string import Template
# If 'rich' is available ("pip install rich" or "apt-get install python3-rich"),
# then use coloured output, otherwise proceed as before
@@ -31,19 +32,78 @@ for given system architecture and MPSD software stack version.\n
The toolchains
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 = {
# kept inside the mpsd_release folder
"cmd_log_file": "install.log",
"build_log_file": (
"logs/mpsd_spack_ver_toolchains_"
f"{datetime.datetime.now().replace(microsecond=0).isoformat()}.log"
# Placeholder installer log file name, placed at mpsd_microarch/logs
"installer_log_template": Template(
"${mpsd_release}_${mpsd_microarch}_${date}_${action}.log"
),
# Placeholder build log file name, placed at mpsd_microarch/logs
"build_log_template": Template(
"${mpsd_release}_${mpsd_microarch}_${date}_${toolchain}_${action}.log"
),
"metadata_tag_open": "!<meta>",
"metadata_tag_close": "</meta>!",
# TODO: modify toolchains,mpsd_spack_ver when the variable is available
"spack_environments_repo": "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git",
}
def create_log_file_names(
mpsd_release: str,
mpsd_microarch: str,
action: str,
date: str = call_date_iso,
toolchain: str = None,
) -> Tuple[str, str]:
"""Create log file names.
This function creates the log file names for the installer and
the build log files.
The installer log file is created
from the output of this script except
the toolchain build log that is handled by the spack_setup.sh script.
The build log `tee`'s the output of the spack_setup.sh script to the log file.
The log file names are created using the
template strings defined in config_vars.
Parameters
----------
mpsd_release : str
MPSD software stack version
mpsd_microarch : str
system architecture
date : str
date of the call ins iso format
action : str
action performed (install,remove,reinstall,prepare,status)
only install and remove are valid for build log file.
toolchain : str
toolchain name (only for build log file)
returns : tuple
tuple containing the strings of installer and build log file names
"""
installer_log_file = config_vars["installer_log_template"].substitute(
mpsd_release=mpsd_release,
mpsd_microarch=mpsd_microarch,
date=date,
action=action,
)
if toolchain and action in ["install", "remove"]:
build_log_file = config_vars["build_log_template"].substitute(
mpsd_release=mpsd_release,
mpsd_microarch=mpsd_microarch,
date=date,
action=action,
toolchain=toolchain,
)
else:
build_log_file = None
logging.warning("Incorrect action or toolchain name.")
return installer_log_file, build_log_file
def log_metadata(key: str, value: str) -> None:
"""Log metadata to the log file.
@@ -516,8 +576,7 @@ def install_environment(
# Set required variables
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.mkdir(parents=True, exist_ok=True)
spack_setup_script = release_base_dir / "spack-environments" / "spack_setup.sh"
@@ -557,11 +616,7 @@ def install_environment(
# _mpsd_spack_ver_ with mpsd_release
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
setup_log_cmd(
mpsd_release,
@@ -679,7 +734,16 @@ def main():
# Carry out the action
args = parser.parse_args()
# Get machine configs
os.environ.get("MPSD_OS", "UNKNOWN_OS")
os.environ.get("MPSD_MICROARCH", "UNKNOWN_MICROARCH")
# 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)
# target dir is the place where this script exists. the
Loading