Skip to content

Commit

Permalink
Merge pull request #29 from bbtufty/gamefinder-logging
Browse files Browse the repository at this point in the history
Improved GameFinder logging
  • Loading branch information
bbtufty authored Aug 27, 2024
2 parents 6245a00 + 5304791 commit 8a5010c
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 38 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ DupeParser

- Logging tidied up to make more readable

GameFinder
~~~~~~~~~~

- Logging tidied up to make more readable

ROMChooser
~~~~~~~~~~

Expand Down Expand Up @@ -56,6 +61,7 @@ General
~~~~~~~

- Due to changes to the re module, ROMSearch requires python>=3.11
- Allowed specifying log level in the config file

0.0.6 (2024-05-23)
==================
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ To get started, see the [documentation](https://romsearch.readthedocs.io/en/late
Currently, ROMSearch is in early development, and so many features may be added over time. At the moment, ROMSearch
works for the following consoles:

* Nintendo - GameCube
* Nintendo - Nintendo Entertainment System
* Nintendo - Super Nintendo Entertainment System
* Sony - PlayStation
* Sony - PlayStation 2
* Sony - PlayStation Portable
* Nintendo
* Nintendo Entertainment System
* Super Nintendo Entertainment System
* GameCube
* Sony
* PlayStation
* PlayStation 2
* PlayStation Portable

but be aware there may be quirks that will only become apparent over time. We encourage users to open
[issues](https://github.com/bbtufty/romsearch/issues) as and where they find them.
4 changes: 4 additions & 0 deletions docs/configs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Syntax: ::
discord: # OPTIONAL. If defined, supply a webhook URL so that ROMSearch can post Discord
webhook_url: [webhook_url] # notifications

logger:
level: info # OPTIONAL. If defined, can set the log level to be printed to terminal and
# logs

Sample
======

Expand Down
17 changes: 11 additions & 6 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ everything and then filter from the downloaded files. For more details, see the
Currently, ROMSearch is in early development, and so many features may be added over time. At the moment, ROMSearch
has the capability for:

* Nintendo - GameCube
* Nintendo - Nintendo Entertainment System
* Nintendo - Super Nintendo Entertainment System
* Sony - PlayStation
* Sony - PlayStation 2
* Sony - PlayStation Portable
* Nintendo

* GameCube
* Nintendo - Nintendo Entertainment System
* Nintendo - Super Nintendo Entertainment System

* Sony

* PlayStation
* PlayStation 2
* PlayStation Portable

but be aware there may be quirks that will only become apparent over time. We encourage users to open
`issues <https://github.com/bbtufty/romsearch/issues>`_ as and where they find them. Known issues can be found at
Expand Down
3 changes: 3 additions & 0 deletions romsearch/configs/sample_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ romchooser:

discord:
webhook_url: "https://discord.com/api/webhooks/discord_url"

logger:
level: debug
49 changes: 44 additions & 5 deletions romsearch/gui/gui_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
from functools import partial

from PySide6.QtCore import Qt
from PySide6.QtGui import QFont
from PySide6.QtWidgets import (QMainWindow,
Expand All @@ -13,6 +11,7 @@
QFrame,
QPlainTextEdit,
)
from functools import partial

import romsearch
from romsearch.util import load_yml, save_yml, load_json, save_json
Expand Down Expand Up @@ -94,12 +93,13 @@ def __init__(self,

super().__init__()

self.ui = main_ui

if logger is None:
logger = get_gui_logger()
log_level = self.ui.radioButtonConfigLoggerLevel.checkedButton().text().lower()
logger = get_gui_logger(log_level=log_level)
self.logger = logger

self.ui = main_ui

# Read in the various pre-set configs we've got
self.mod_dir = os.path.dirname(romsearch.__file__)

Expand Down Expand Up @@ -354,6 +354,7 @@ def load_config(self,
self.set_checkboxes()
self.set_text_fields()
self.set_romsearch_method()
self.set_logger_level()
self.set_includes_excludes()

def set_directory_name(self,
Expand Down Expand Up @@ -524,6 +525,29 @@ def set_romsearch_method(self):

return True

def set_logger_level(self):
"""Set the logger level from the config file"""

if "logger" not in self.config:
return False

if "level" in self.config["logger"]:

level = self.config["logger"]["level"]

if level == "debug":
button = self.ui.radioButtonConfigLoggerLevelDebug
elif level == "info":
button = self.ui.radioButtonConfigLoggerLevelInfo
elif level == "critical":
button = self.ui.radioButtonConfigLoggerLevelCritical
else:
raise ValueError(f"Do not understand logger level {level}")

button.setChecked(True)

return True

def set_includes_excludes(self):
"""Set any includes/excludes config file"""

Expand Down Expand Up @@ -606,6 +630,9 @@ def save_config(self):
# Dat filters we do a bit differently
self.get_dat_filters()

# Finally, the logger level
self.get_logger_level()

# Save out the config file
save_yml(filename, self.config)

Expand Down Expand Up @@ -787,3 +814,15 @@ def get_dat_filters(self):
self.config["romchooser"]["dat_filters"] = dat_filters

return True

def get_logger_level(self):
"""Get the logger level from the button config"""

if "logger" not in self.config:
self.config["logger"] = {}

# Get the method from the radio button group
logger_level = self.ui.radioButtonConfigLoggerLevel.checkedButton().text().lower()
self.config["logger"]["level"] = logger_level

return True
7 changes: 4 additions & 3 deletions romsearch/gui/gui_romsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ def __init__(self):

super().__init__()

self.logger = get_gui_logger()
self.logger.warning("Do not close this window!")

self.ui = Ui_RomSearch()
self.ui.setupUi(self)

log_level = self.ui.radioButtonConfigLoggerLevel.checkedButton().text().lower()
self.logger = get_gui_logger(log_level=log_level)
self.logger.warning("Do not close this window!")

# Set up the worker threads for later
self.romsearch_thread = None
self.romsearch_worker = None
Expand Down
82 changes: 80 additions & 2 deletions romsearch/gui/layout_romsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Ui_RomSearch(object):
def setupUi(self, RomSearch):
if not RomSearch.objectName():
RomSearch.setObjectName(u"RomSearch")
RomSearch.resize(950, 785)
RomSearch.resize(1036, 798)
sizePolicy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand Down Expand Up @@ -1182,6 +1182,79 @@ def setupUi(self, RomSearch):
self.horizontalLayout_8.addLayout(self.gridLayoutConfigDiscord)

self.tabWidgetConfig.addTab(self.tabConfigDiscord, "")
self.tabConfigLogger = QWidget()
self.tabConfigLogger.setObjectName(u"tabConfigLogger")
self.gridLayout_2 = QGridLayout(self.tabConfigLogger)
self.gridLayout_2.setObjectName(u"gridLayout_2")
self.gridLayoutConfigLogger = QGridLayout()
self.gridLayoutConfigLogger.setObjectName(u"gridLayoutConfigLogger")
self.gridLayoutConfigLoggerLeft = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)

self.gridLayoutConfigLogger.addItem(self.gridLayoutConfigLoggerLeft, 0, 1, 1, 1)

self.gridLayoutConfigLoggerMiddle = QGridLayout()
self.gridLayoutConfigLoggerMiddle.setObjectName(u"gridLayoutConfigLoggerMiddle")
self.labelConfigLoggerLevelTitle = QLabel(self.tabConfigLogger)
self.labelConfigLoggerLevelTitle.setObjectName(u"labelConfigLoggerLevelTitle")
self.labelConfigLoggerLevelTitle.setFont(font)
self.labelConfigLoggerLevelTitle.setAlignment(Qt.AlignmentFlag.AlignCenter)

self.gridLayoutConfigLoggerMiddle.addWidget(self.labelConfigLoggerLevelTitle, 2, 0, 1, 1)

self.lineConfigLoggerLevelDividerTop = QFrame(self.tabConfigLogger)
self.lineConfigLoggerLevelDividerTop.setObjectName(u"lineConfigLoggerLevelDividerTop")
self.lineConfigLoggerLevelDividerTop.setFrameShadow(QFrame.Shadow.Plain)
self.lineConfigLoggerLevelDividerTop.setFrameShape(QFrame.Shape.HLine)

self.gridLayoutConfigLoggerMiddle.addWidget(self.lineConfigLoggerLevelDividerTop, 1, 0, 1, 1)

self.lineConfigLoggerLevelDividerBottom = QFrame(self.tabConfigLogger)
self.lineConfigLoggerLevelDividerBottom.setObjectName(u"lineConfigLoggerLevelDividerBottom")
self.lineConfigLoggerLevelDividerBottom.setFrameShadow(QFrame.Shadow.Plain)
self.lineConfigLoggerLevelDividerBottom.setFrameShape(QFrame.Shape.HLine)

self.gridLayoutConfigLoggerMiddle.addWidget(self.lineConfigLoggerLevelDividerBottom, 6, 0, 1, 1)

self.radioButtonConfigLoggerLevelInfo = QRadioButton(self.tabConfigLogger)
self.radioButtonConfigLoggerLevel = QButtonGroup(RomSearch)
self.radioButtonConfigLoggerLevel.setObjectName(u"radioButtonConfigLoggerLevel")
self.radioButtonConfigLoggerLevel.addButton(self.radioButtonConfigLoggerLevelInfo)
self.radioButtonConfigLoggerLevelInfo.setObjectName(u"radioButtonConfigLoggerLevelInfo")
self.radioButtonConfigLoggerLevelInfo.setChecked(True)

self.gridLayoutConfigLoggerMiddle.addWidget(self.radioButtonConfigLoggerLevelInfo, 4, 0, 1, 1)

self.verticalSpacerConfigLoggerBottom = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)

self.gridLayoutConfigLoggerMiddle.addItem(self.verticalSpacerConfigLoggerBottom, 7, 0, 1, 1)

self.verticalSpacerConfigLoggerTop = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)

self.gridLayoutConfigLoggerMiddle.addItem(self.verticalSpacerConfigLoggerTop, 0, 0, 1, 1)

self.radioButtonConfigLoggerLevelDebug = QRadioButton(self.tabConfigLogger)
self.radioButtonConfigLoggerLevel.addButton(self.radioButtonConfigLoggerLevelDebug)
self.radioButtonConfigLoggerLevelDebug.setObjectName(u"radioButtonConfigLoggerLevelDebug")

self.gridLayoutConfigLoggerMiddle.addWidget(self.radioButtonConfigLoggerLevelDebug, 3, 0, 1, 1)

self.radioButtonConfigLoggerLevelCritical = QRadioButton(self.tabConfigLogger)
self.radioButtonConfigLoggerLevel.addButton(self.radioButtonConfigLoggerLevelCritical)
self.radioButtonConfigLoggerLevelCritical.setObjectName(u"radioButtonConfigLoggerLevelCritical")

self.gridLayoutConfigLoggerMiddle.addWidget(self.radioButtonConfigLoggerLevelCritical, 5, 0, 1, 1)


self.gridLayoutConfigLogger.addLayout(self.gridLayoutConfigLoggerMiddle, 0, 2, 1, 1)

self.gridLayoutConfigLoggerRight = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)

self.gridLayoutConfigLogger.addItem(self.gridLayoutConfigLoggerRight, 0, 3, 1, 1)


self.gridLayout_2.addLayout(self.gridLayoutConfigLogger, 0, 0, 1, 1)

self.tabWidgetConfig.addTab(self.tabConfigLogger, "")

self.verticalLayout_2.addWidget(self.tabWidgetConfig)

Expand Down Expand Up @@ -1218,7 +1291,7 @@ def setupUi(self, RomSearch):
RomSearch.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(RomSearch)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 950, 33))
self.menubar.setGeometry(QRect(0, 0, 1036, 33))
self.menuFile = QMenu(self.menubar)
self.menuFile.setObjectName(u"menuFile")
self.menuHelp = QMenu(self.menubar)
Expand Down Expand Up @@ -1501,6 +1574,11 @@ def retranslateUi(self, RomSearch):
self.lineEditConfigDiscordWebhookUrl.setText("")
self.lineEditConfigDiscordWebhookUrl.setPlaceholderText(QCoreApplication.translate("RomSearch", u"https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", None))
self.tabWidgetConfig.setTabText(self.tabWidgetConfig.indexOf(self.tabConfigDiscord), QCoreApplication.translate("RomSearch", u"Discord", None))
self.labelConfigLoggerLevelTitle.setText(QCoreApplication.translate("RomSearch", u"Log level", None))
self.radioButtonConfigLoggerLevelInfo.setText(QCoreApplication.translate("RomSearch", u"Info", None))
self.radioButtonConfigLoggerLevelDebug.setText(QCoreApplication.translate("RomSearch", u"Debug", None))
self.radioButtonConfigLoggerLevelCritical.setText(QCoreApplication.translate("RomSearch", u"Critical", None))
self.tabWidgetConfig.setTabText(self.tabWidgetConfig.indexOf(self.tabConfigLogger), QCoreApplication.translate("RomSearch", u"Logger", None))
self.tabWidgetModules.setTabText(self.tabWidgetModules.indexOf(self.tabConfig), QCoreApplication.translate("RomSearch", u"Config", None))
#if QT_CONFIG(statustip)
self.pushButtonExit.setStatusTip(QCoreApplication.translate("RomSearch", u"Exit ROMSearch", None))
Expand Down
Loading

0 comments on commit 8a5010c

Please sign in to comment.