forked from metabrainz/picard
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to select extra debug output
Web service replies can be very long, and it makes debug output rather hard to read. A debug option mechanism is now added, it is controlled by a new class `DebugOpt`. A command-line option `--debug-opts` allows selection of extra debug output, for now the sole option is `ws_replies`. A matching menu was added in View Debug Log dialog. It is important to note those aren't saved in config file, as they are meant to be disabled by default and only enabled when needed.
- Loading branch information
Showing
5 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2024 Laurent Monin | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from enum import IntEnum | ||
|
||
|
||
class DebugOptMeta(IntEnum): | ||
|
||
@property | ||
def optname(self): | ||
return self.name.lower() | ||
|
||
@property | ||
def title(self): | ||
return self._descriptions[self][0] | ||
|
||
@property | ||
def description(self): | ||
return self._descriptions[self][1] | ||
|
||
@property | ||
def enabled(self): | ||
return self in self._registry | ||
|
||
@enabled.setter | ||
def enabled(self, enable): | ||
if enable: | ||
self._registry.add(self) | ||
else: | ||
self._registry.discard(self) | ||
|
||
@classmethod | ||
def set_registry(cls, registry): | ||
cls._registry = registry | ||
|
||
@classmethod | ||
def set_descriptions(cls, descriptions): | ||
cls._descriptions = descriptions | ||
|
||
@classmethod | ||
def opt_names(cls): | ||
"""Returns a string listing all valid names for debug options""" | ||
return ",".join(sorted(o.optname for o in cls)) | ||
|
||
@classmethod | ||
def from_string(cls, string): | ||
"""Parse command line argument, a string with comma-separated values, | ||
and enable corresponding debug options""" | ||
opts = {str(o).strip().lower() for o in string.split(',')} | ||
for o in cls: | ||
o.enabled = o.optname in opts | ||
|
||
|
||
class DebugOpt(DebugOptMeta): | ||
WS_REPLIES = 1 | ||
|
||
|
||
DebugOpt.set_descriptions({ | ||
DebugOpt.WS_REPLIES: (N_('WS Replies'), N_('Log web service replies')), | ||
}) | ||
_debug_opts = set() | ||
DebugOpt.set_registry(_debug_opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2024 Laurent Monin | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from test.picardtestcase import PicardTestCase | ||
|
||
from picard.debug_opts import DebugOptMeta | ||
|
||
|
||
class TestDebugOpt(DebugOptMeta): | ||
A = 1 | ||
B = 2 | ||
|
||
|
||
_descriptions = { | ||
TestDebugOpt.A: ('titleA', 'descA'), | ||
TestDebugOpt.B: ('titleB', 'descB'), | ||
} | ||
TestDebugOpt.set_descriptions(_descriptions) | ||
|
||
|
||
class DebugOptTest(PicardTestCase): | ||
def setUp(self): | ||
TestDebugOpt.set_registry(set()) | ||
|
||
def test_enabled(self): | ||
self.assertFalse(TestDebugOpt.A.enabled) | ||
self.assertFalse(TestDebugOpt.B.enabled) | ||
TestDebugOpt.A.enabled = True | ||
self.assertTrue(TestDebugOpt.A.enabled) | ||
|
||
def test_optname(self): | ||
self.assertEqual(TestDebugOpt.A.optname, 'a') | ||
self.assertEqual(TestDebugOpt.B.optname, 'b') | ||
|
||
def test_title(self): | ||
self.assertEqual(TestDebugOpt.A.title, _descriptions[TestDebugOpt.A][0]) | ||
self.assertEqual(TestDebugOpt.B.title, _descriptions[TestDebugOpt.B][0]) | ||
|
||
def test_description(self): | ||
self.assertEqual(TestDebugOpt.A.description, _descriptions[TestDebugOpt.A][1]) | ||
self.assertEqual(TestDebugOpt.B.description, _descriptions[TestDebugOpt.B][1]) | ||
|
||
def test_opt_names(self): | ||
self.assertEqual(TestDebugOpt.opt_names(), 'a,b') | ||
|
||
def test_from_string_simple(self): | ||
TestDebugOpt.from_string('a') | ||
self.assertTrue(TestDebugOpt.A.enabled) | ||
self.assertFalse(TestDebugOpt.B.enabled) | ||
TestDebugOpt.from_string('a,b') | ||
self.assertTrue(TestDebugOpt.A.enabled) | ||
self.assertTrue(TestDebugOpt.B.enabled) | ||
|
||
def test_from_string_complex(self): | ||
TestDebugOpt.from_string('something, A,x,b') | ||
self.assertTrue(TestDebugOpt.A.enabled) | ||
self.assertTrue(TestDebugOpt.B.enabled) | ||
|
||
def test_from_string_remove(self): | ||
TestDebugOpt.set_registry({TestDebugOpt.B}) | ||
self.assertTrue(TestDebugOpt.B.enabled) | ||
TestDebugOpt.from_string('A') | ||
self.assertTrue(TestDebugOpt.A.enabled) | ||
self.assertFalse(TestDebugOpt.B.enabled) |