moved log_error into Error.py

This commit is contained in:
Faraphel 2022-01-26 09:07:39 +01:00
parent 2b9f9d8354
commit abce32c3c8
4 changed files with 38 additions and 26 deletions

View file

@ -4,6 +4,7 @@ from source.Game import Game
from source.Gui.Main import Main
from source.Gui.TrackConfiguration import TrackConfiguration
from source.Translation import Translator
from source.Error import ErrorLogger
class Common:
@ -16,6 +17,8 @@ class Common:
self.json_frame_filter = None
self.translator = Translator(common=self)
self.translate = self.translator.translate # shortcut for the method
self.errorlogger = ErrorLogger(common=self)
self.log_error = self.errorlogger.log_error # shortcut for the method
self.option = Option().load_from_file("./option.json")
self.ct_config = CT_Config()

View file

@ -1,3 +1,8 @@
from tkinter import messagebox
import traceback
import os
class RomAlreadyPatched(Exception):
def __init__(self):
super().__init__("ROM Already patched !")
@ -31,3 +36,28 @@ class CantConvertTrack(Exception):
class MissingTrackWU8(Exception):
def __init__(self):
super().__init__("The original wu8 track file is missing !")
class ErrorLogger:
def __init__(self, common):
self.common = common
def log_error(self) -> None:
"""
When an error occur, will show it in a messagebox and write it in error.log
"""
error = traceback.format_exc()
with open("./error.log", "a") as f:
f.write(
f"---\n"
f"For game version : {self.common.ct_config.version}\n"
f"./file/ directory : {os.listdir('./file/')}\n"
f"ctconfig directory : {os.listdir(self.common.ct_config.pack_path)}\n"
f"GAME/files/ information : {self.common.game.path, self.common.game.region}\n"
f"{error}\n"
)
messagebox.showerror(
self.common.translate("Error"),
self.common.translate("An error occured", " :", "\n", error, "\n\n")
)

View file

@ -1,4 +1,3 @@
from tkinter import messagebox
from PIL import Image, ImageDraw, ImageFont
import shutil
import glob
@ -264,7 +263,7 @@ class Game:
messagebox.showinfo(self.common.translate("End"), self.common.translate("The mod have been installed !"))
except Exception as e:
self.common.gui_main.log_error()
self.common.log_error()
raise e
finally:
@ -442,7 +441,7 @@ class Game:
self.patch_tracks()
except Exception as e:
self.common.gui_main.log_error()
self.common.log_error()
raise e
finally:

View file

@ -1,8 +1,7 @@
from distutils.version import StrictVersion
from tkinter import filedialog, ttk, messagebox
from tkinter import filedialog, ttk
from tkinter import *
import webbrowser
import traceback
import requests
import zipfile
import glob
@ -105,7 +104,7 @@ class Main:
messagebox.showerror(self.common.translate("Error"), self.common.translate("This game's format is invalid"))
raise InvalidFormat
except Exception as e:
self.log_error()
self.common.log_error()
raise e
finally:
self.progress(show=False)
@ -309,26 +308,7 @@ class Main:
self.common.option.disable_download = True
except:
self.log_error()
def log_error(self) -> None:
"""
When an error occur, will show it in a messagebox and write it in error.log
"""
error = traceback.format_exc()
with open("./error.log", "a") as f:
f.write(
f"---\n"
f"For game version : {self.common.ct_config.version}\n"
f"./file/ directory : {os.listdir('./file/')}\n"
f"ctconfig directory : {os.listdir(self.common.ct_config.pack_path)}\n"
f"GAME/files/ information : {self.common.game.path, self.common.game.region}\n"
f"{error}\n"
)
messagebox.showerror(
self.common.translate("Error"),
self.common.translate("An error occured", " :", "\n", error, "\n\n")
)
self.common.log_error()
def progress(self, show: bool = None, indeter: bool = None, step: int = None,
statut: str = None, max: int = None, add: int = None) -> None: