diff --git a/mpsd-software-environment.py b/mpsd-software-environment.py index 2353a5edebc45a6acc42a2a5c154c4a3372bd263..496466a241c832bcd623df2a6571658c265f4812 100755 --- a/mpsd-software-environment.py +++ b/mpsd-software-environment.py @@ -151,6 +151,29 @@ def read_metadata_from_logfile(logfile: Union[str, Path]) -> dict: } +def get_installer_log_file(args: argparse.Namespace, script_dir: str) -> str: + """Get installer log file name.""" + # Get machine configs + os.environ.get("MPSD_OS", "UNKNOWN_OS") + mpsd_microarch = get_native_microarchitecture() + mpsd_release = args.release + # parse logging first + # decide the log_file_name + installer_log_name, build_log_name = create_log_file_names( + mpsd_release=mpsd_release, mpsd_microarch=mpsd_microarch, action=args.action + ) + log_folder = script_dir / mpsd_release / mpsd_microarch / "logs" + # if the log_folder dosent exist, dont log this message if + # the command is a info-only command + if args.action not in ["status", "available"]: + if not os.path.exists(log_folder): + os.makedirs(log_folder) + installer_log_file = log_folder / installer_log_name + else: + installer_log_file = None + return installer_log_file + + def set_up_logging(loglevel="warning", filename=None): """Set up logging. @@ -885,26 +908,9 @@ def main(): # Carry out the action args = parser.parse_args() - # Get machine configs - os.environ.get("MPSD_OS", "UNKNOWN_OS") - mpsd_microarch = get_native_microarchitecture() # target dir is the place where this script exists. the script_dir = Path(os.path.dirname(os.path.realpath(__file__))) - mpsd_release = args.release - # parse logging first - # decide the log_file_name - installer_log_name, build_log_name = create_log_file_names( - mpsd_release=mpsd_release, mpsd_microarch=mpsd_microarch, action=args.action - ) - log_folder = script_dir / mpsd_release / mpsd_microarch / "logs" - # if the log_folder dosent exist, dont log this message if - # the command is a info-only command - if args.action not in ["status", "available"]: - if not os.path.exists(log_folder): - os.makedirs(log_folder) - installer_log_file = log_folder / installer_log_name - else: - installer_log_file = None + installer_log_file = get_installer_log_file(args, script_dir) set_up_logging(args.loglevel, installer_log_file) diff --git a/tests.py b/tests.py index 1fd13cd0e344d891620a7d634868c03d9265e86b..fb43939a3d39da77d1f7263a1c3d640678fff75f 100644 --- a/tests.py +++ b/tests.py @@ -269,7 +269,6 @@ def test_install_environment_zlib(): with open(setup_file, "w") as f: f.write(lines) - # install global_generic toolchain mod.install_environment( mpsd_release=mpsd_release_to_test, @@ -317,9 +316,8 @@ def test_install_environment_zlib(): lines = f.read() assert "zlib" in lines - - # install again to ensure that - # commands that skip creation of folders when + # install again to ensure that + # commands that skip creation of folders when # they are already present works as expected # reload the module to ensure that date changes importlib.reload(mod) @@ -337,7 +335,6 @@ def test_install_environment_zlib(): assert len(build_log) > 1 - def test_metadata_logging(tmp_path): """Test that metadata is logged and read correctly.""" # Test that the metadata is logged correctly