-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoltergust.py
67 lines (52 loc) · 2.12 KB
/
poltergust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging, os, sys
from tkinter import *
from tkinter import messagebox
from dotenv import load_dotenv
from poltergust.controllers.ghostinfos_controller import PoltergustController
from poltergust.models.ct_storage import MK8CTStorage
from poltergust.views.main_view import PoltergustMainView
if __name__ == '__main__':
# Load environment variables
load_dotenv(".env")
# Logging config
logging_config = {}
# Log to file
logfile = os.getenv("LOGFILE", "error.log")
if logfile:
logging_config['filename'] = logfile
# Set other config
logging.basicConfig(
encoding='utf-8',
level=os.getenv("LOGLEVEL", "WARNING"),
format="[%(levelname)s] <%(asctime)s> %(name)s: %(message)s",
datefmt='%Y-%m-%d %H:%M:%S',
**logging_config
)
# Pass unhandled exceptions to logger
def on_unhandled_exception_base(exctype, exc, tb):
logging.error("An unhandled exception occurred.", exc_info=(exctype, exc, tb))
# Show messagebox on unhandled exception
def on_unhandled_exception_messagebox(exctype, exc, tb):
on_unhandled_exception_base(exctype, exc, tb)
messagebox.showerror(
"ERROR: Unhandled Exception occurred!",
f"Oh no, something went terribly wrong! Please report the issue, and include error.log and (if applicable) the current ghost file.\n\n{exctype.__name__}: {exc}"
)
# Show messagebox on error?
unhandled_exc_hook = on_unhandled_exception_base
if os.getenv("MESSAGEBOX_ON_ERROR", 1) == 1:
unhandled_exc_hook = on_unhandled_exception_messagebox
# Override default stderr
sys.excepthook = unhandled_exc_hook
# Override Tkinter stderr
root = Tk()
root.report_callback_exception = unhandled_exc_hook
# Create and display the UI
view = PoltergustMainView(root)
controller = PoltergustController(view)
# Immediately open file if passed in
if len(sys.argv) == 2:
# Replace \ by / path separators (for Windows)
controller.open_ghostfile(sys.argv[1].replace("\\", "/"))
logging.info("Starting Poltergust")
root.mainloop()