mirror of
https://github.com/dortania/OpenCore-Legacy-Patcher.git
synced 2026-04-17 21:24:40 +10:00
Implement logging library
This commit is contained in:
@@ -5,6 +5,7 @@ import sys
|
||||
from pathlib import Path
|
||||
import time
|
||||
import threading
|
||||
import logging
|
||||
|
||||
from resources import cli_menu, constants, utilities, device_probe, os_probe, defaults, arguments, install, tui_helpers, reroute_payloads, commit_info
|
||||
from resources.build import build
|
||||
@@ -12,9 +13,12 @@ from data import model_array
|
||||
|
||||
class OpenCoreLegacyPatcher:
|
||||
def __init__(self, launch_gui=False):
|
||||
print("- Loading...")
|
||||
self.constants = constants.Constants()
|
||||
self.constants.wxpython_variant = launch_gui
|
||||
self.initialize_logging()
|
||||
|
||||
logging.info(f"- Loading OpenCore Legacy Patcher v{self.constants.patcher_version}...")
|
||||
|
||||
self.generate_base_data()
|
||||
if utilities.check_cli_args() is None:
|
||||
if launch_gui is True:
|
||||
@@ -24,6 +28,18 @@ class OpenCoreLegacyPatcher:
|
||||
else:
|
||||
self.main_menu()
|
||||
|
||||
def initialize_logging(self):
|
||||
logging.basicConfig(
|
||||
level=logging.NOTSET,
|
||||
format="%(asctime)s - %(filename)s (%(lineno)d): %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler(f"Library/Logs/OpenCore-Patcher-v{self.constants.patcher_version}.log"),
|
||||
logging.StreamHandler(),
|
||||
],
|
||||
)
|
||||
logging.getLogger().handlers[1].setFormatter(logging.Formatter("%(message)s"))
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
def generate_base_data(self):
|
||||
self.constants.detected_os = os_probe.detect_kernel_major()
|
||||
self.constants.detected_os_minor = os_probe.detect_kernel_minor()
|
||||
@@ -58,14 +74,14 @@ class OpenCoreLegacyPatcher:
|
||||
defaults.generate_defaults(self.computer.real_model, True, self.constants)
|
||||
|
||||
if utilities.check_cli_args() is not None:
|
||||
print("- Detected arguments, switching to CLI mode")
|
||||
logging.info("- Detected arguments, switching to CLI mode")
|
||||
self.constants.gui_mode = True # Assumes no user interaction is required
|
||||
ignore_args = ["--auto_patch", "--gui_patch", "--gui_unpatch"]
|
||||
if not any(x in sys.argv for x in ignore_args):
|
||||
self.constants.current_path = Path.cwd()
|
||||
self.constants.cli_mode = True
|
||||
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
|
||||
print("- Rerouting payloads location")
|
||||
logging.info("- Rerouting payloads location")
|
||||
self.constants.payload_path = sys._MEIPASS / Path("payloads")
|
||||
ignore_args = ignore_args.pop(0)
|
||||
if not any(x in sys.argv for x in ignore_args):
|
||||
@@ -73,7 +89,7 @@ class OpenCoreLegacyPatcher:
|
||||
time.sleep(0.1)
|
||||
arguments.arguments().parse_arguments(self.constants)
|
||||
else:
|
||||
print(f"- No arguments present, loading {'GUI' if self.constants.wxpython_variant is True else 'TUI'} mode")
|
||||
logging.info(f"- No arguments present, loading {'GUI' if self.constants.wxpython_variant is True else 'TUI'} mode")
|
||||
|
||||
|
||||
def main_menu(self):
|
||||
|
||||
Reference in New Issue
Block a user