diff --git a/src/antares_web_installer/gui/controller.py b/src/antares_web_installer/gui/controller.py index bae503a..bb1bb23 100644 --- a/src/antares_web_installer/gui/controller.py +++ b/src/antares_web_installer/gui/controller.py @@ -9,7 +9,7 @@ from pathlib import Path import psutil -from platformdirs import user_log_dir +from platformdirs import user_runtime_dir from .mvc import Controller, Model, View from .model import WizardModel @@ -37,7 +37,7 @@ def __post_init__(self): self.initialize_log_path() def initialize_log_path(self): - self.log_path = Path(user_log_dir("AntaresWebInstaller", "RTE")) + self.log_path = Path(user_runtime_dir("AntaresWebInstaller", "RTE")) if not self.log_path.exists(): msg = "No log directory found with path '{}'.".format(self.log_path) logger.warning(msg) diff --git a/src/antares_web_installer/gui/widgets/frame.py b/src/antares_web_installer/gui/widgets/frame.py index 16ed3c4..fb76d90 100644 --- a/src/antares_web_installer/gui/widgets/frame.py +++ b/src/antares_web_installer/gui/widgets/frame.py @@ -1,4 +1,5 @@ import logging +import shutil import tkinter as tk import typing from threading import Thread @@ -253,14 +254,16 @@ def __init__(self, master: tk.Misc, window: "WizardView", index: int, *args, **k # thread handling self.thread = None + self.log_manager = None + self.file_logger = None def progress_update(self, value: float): self.progress_bar["value"] = value def initialize_user_log_manager(self, logger): # One log after another is displayed in the main window - log_manager = LogManager(self) - logger.addHandler(log_manager) + self.log_manager = LogManager(self) + logger.addHandler(self.log_manager) def initialize_file_log_manager(self, logger): from antares_web_installer.gui.controller import WizardController @@ -290,15 +293,15 @@ def on_active_frame(self, event): main_logger = logging.getLogger("antares_web_installer.app") # Initialize log manager - log_manager = LogManager(self) - main_logger.addHandler(log_manager) + self.log_manager = LogManager(self) + main_logger.addHandler(self.log_manager) if isinstance(self.window.controller, WizardController): # redirect logs in the target `tmp` directory - file_logger = logging.FileHandler(self.window.get_log_file()) - file_logger.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")) - file_logger.setLevel(logging.INFO) - main_logger.addHandler(file_logger) + self.file_logger = logging.FileHandler(self.window.get_log_file()) + self.file_logger.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")) + self.file_logger.setLevel(logging.INFO) + main_logger.addHandler(self.file_logger) # Launching installation in concurrency with the current process self.thread = Thread(target=self.window.controller.install, args=()) @@ -309,15 +312,6 @@ def on_active_frame(self, event): self.window.raise_error(msg) def on_installation_complete(self, event): - # Lazy import for typing and testing purposes - from antares_web_installer.gui.controller import WizardController - - if isinstance(self.window.controller, WizardController): - # move log file in application log directory - file_name = self.window.controller.log_file.name - log_directory = self.window.controller.target_dir.joinpath("logs") - self.window.get_log_file().rename(self.window.controller.target_dir.joinpath(log_directory, file_name)) - self.control_btn.btns["next"].toggle_btn(True) @@ -336,3 +330,16 @@ def __init__(self, master: tk.Misc, window: "WizardView", index: int, *args, **k self.control_btn = ControlFrame(parent=self, window=window, finish_btn=True) self.control_btn.pack(side="bottom", fill="x") + + self.bind("<>", self.on_active_frame) + + def on_active_frame(self, event): + # Lazy import for typing and testing purposes + from antares_web_installer.gui.controller import WizardController + + if isinstance(self.window.controller, WizardController): + # copy log file in application log directory + file_name = self.window.controller.log_file.name + log_directory = self.window.controller.target_dir.joinpath("logs") + # self.window.get_log_file().rename(self.window.controller.target_dir.joinpath(log_directory, file_name)) + shutil.copy(self.window.get_log_file(), log_directory.joinpath(file_name))