Skip to content

Commit

Permalink
fix(WizardController.install): use runtime directory to store tempora…
Browse files Browse the repository at this point in the history
…ry log files
  • Loading branch information
maugde committed Jul 23, 2024
1 parent 5ae6097 commit 70831ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/antares_web_installer/gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 24 additions & 17 deletions src/antares_web_installer/gui/widgets/frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import shutil
import tkinter as tk
import typing
from threading import Thread
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=())
Expand All @@ -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)


Expand All @@ -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("<<ActivateFrame>>", 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))

0 comments on commit 70831ff

Please sign in to comment.