diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 45ab731f121ff1a28dd7a267eb446623440f5d75..7747762c822ef7e64f47cdcfc6459378a6537995 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -137,7 +137,7 @@ def read_metadata_from_logfile(logfile: Union[str, Path]) -> dict: } -def create_log_file_names( +def create_log_file_name( mpsd_release: str, microarch: str, action: str, @@ -166,7 +166,7 @@ def create_log_file_names( action : str action performed (install,remove,reinstall,prepare,status) only install and remove are valid for build log file. - package_set : str + package_set : str or None package_set name (only for build log file) Returns @@ -175,8 +175,48 @@ def create_log_file_names( log file name installer_log_file_name or build_log_file_name depending on the parameters given. - If the action is not one that changes the files on disk ( info only actions) + If the action is not one that changes the files on disk (info only actions) then None is returned. + + Examples + -------- + # installer log file name for `mpsd-software install dev-23a foss2021a-mpi` + >>> create_log_file_name( + ... "dev-23a", + ... "sandybridge", + ... "install", + ... "2023-07-03T12-27-52", + ... ) + 'dev-23a_sandybridge_2023-07-03T12-27-52_APEX_install.log' + + # build log file name for `mpsd-software install dev-23a foss2021a-mpi` + >>> create_log_file_name( + ... "dev-23a", + ... "sandybridge", + ... "install", + ... "2023-07-03T12-27-52", + ... "foss2021a-mpi", + ... ) + 'dev-23a_sandybridge_2023-07-03T12-27-52_BUILD_foss2021a-mpi_install.log' + + # installer log file name for `mpsd-software status dev-23a` + >>> create_log_file_name( + ... "dev-23a", + ... "sandybridge", + ... "status", + ... "2023-07-03T12-27-52", + ... ) + 'dev-23a_sandybridge_2023-07-03T12-27-52_APEX_status.log' + + # build log file name for `mpsd-software status dev-23a` (no log file is created) + >>> create_log_file_name( + ... "dev-23a", + ... "sandybridge", + ... "status", + ... "2023-07-03T12-27-52", + ... "foss2021a-mpi", + ... ) + (None) """ if package_set: # if package_set is given, then we build the build_log_file_name @@ -196,7 +236,7 @@ def create_log_file_names( def get_log_file_path( mpsd_release: str, cmd: str, root_dir: Path, package_set: Union[str, None] = None ) -> Union[Path, None]: - """Get installer log file path. + """Get log file path. This function creates the log file paths for either the installer or the build log files. @@ -223,10 +263,54 @@ def get_log_file_path( log file path installer_log_file_path or build_log_file_path depending on the parameters given. + + Examples + -------- + # installer log file path for `mpsd-software install dev-23a foss2021a-mpi` + >>> get_log_file_path( + ... "dev-23a", + ... "install", + ... Path( + ... "/tmp/root_dir" + ... ), + ... ) + PosixPath('/tmp/root_dir/dev-23a/logs/dev-23a_zen3_2023-07-03T12-28-55_APEX_install.log') + + # build log file path for `mpsd-software install dev-23a foss2021a-mpi` + >>> get_log_file_path( + ... "dev-23a", + ... "install", + ... Path( + ... "/tmp/root_dir" + ... ), + ... "foss2021a-mpi", + ... ) + PosixPath('/tmp/root_dir/dev-23a/logs/dev-23a_zen3_2023-07-03T12-28-55_BUILD_foss2021a-mpi_install.log') + + # installer log file path for `mpsd-software status dev-23a` + >>> get_log_file_path( + ... "dev-23a", + ... "status", + ... Path( + ... "/tmp/root_dir" + ... ), + ... ) + PosixPath('/tmp/root_dir/dev-23a/logs/dev-23a_zen3_2023-07-03T12-28-55_APEX_status.log') + + # build log file path for `mpsd-software status dev-23a` (no log file is created) + >>> get_log_file_path( + ... "dev-23a", + ... "status", + ... Path( + ... "/tmp/root_dir" + ... ), + ... "foss2021a-mpi", + ... ) + (None) """ # Get machine configs microarch = get_native_microarchitecture() - log_file_name = create_log_file_names( + log_file_name = create_log_file_name( mpsd_release=mpsd_release, microarch=microarch, action=cmd, diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 09774d57f69e15fe507af10456fe0c2c8172579c..0b5489e74fdc97830b26565ffb1051ff7c73d1bd 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -417,16 +417,16 @@ def test_get_available_package_sets(): ) -def test_create_log_file_names(): +def test_create_log_file_name(): """Test that the log file names are created correctly.""" - create_log_file_names = mod.create_log_file_names + create_log_file_name = mod.create_log_file_name mpsd_release = "dev-23a" microarch = "sandybridge" date = datetime.datetime.now().replace(microsecond=0).isoformat() action = "install" package_set = "foss2021a" # test build_log_file_name generation - build_log_file_name = create_log_file_names( + build_log_file_name = create_log_file_name( microarch=microarch, mpsd_release=mpsd_release, date=date, @@ -437,7 +437,7 @@ def test_create_log_file_names(): build_log_file_name == f"{mpsd_release}_{microarch}_{date}_BUILD_{package_set}_{action}.log" ) - installer_log_file_name = create_log_file_names( + installer_log_file_name = create_log_file_name( microarch=microarch, mpsd_release=mpsd_release, date=date, @@ -448,7 +448,7 @@ def test_create_log_file_names(): == f"{mpsd_release}_{microarch}_{date}_APEX_{action}.log" ) # test no build log file for incorrect action - build_log_file_name = create_log_file_names( + build_log_file_name = create_log_file_name( microarch=microarch, mpsd_release=mpsd_release, date=date,