Introduce DebugOpt.PLUGIN_FULLPATH and shorten plugin paths in logs

This commit is contained in:
Laurent Monin
2024-04-12 12:12:44 +02:00
parent fb91b929da
commit eb21f7edb0
3 changed files with 57 additions and 0 deletions

View File

@@ -78,3 +78,4 @@ class DebugOptEnum(int, Enum):
class DebugOpt(DebugOptEnum):
WS_REPLIES = 1, N_('Web Service Replies'), N_('Log content of web service replies')
PLUGIN_FULLPATH = 2, N_('Plugin Fullpath'), N_('Log plugin full paths')

View File

@@ -45,6 +45,7 @@ from picard.const.sys import (
FROZEN_TEMP_PATH,
IS_FROZEN,
)
from picard.debug_opts import DebugOpt
# Get the absolute path for the picard module
@@ -176,6 +177,12 @@ def name_filter(record):
path = path.resolve().relative_to(picard_module_path)
except ValueError:
pass
else:
if not DebugOpt.PLUGIN_FULLPATH.enabled and 'plugins' in path.parts:
parts = list(reversed(path.parts))
parts = parts[:parts.index('plugins') + 1]
path = Path(*reversed(parts))
parts = list(path.parts)
if parts[-1] == '__init__':
del parts[-1]

View File

@@ -33,6 +33,7 @@ from unittest.mock import patch
from test.picardtestcase import PicardTestCase
from picard.const.sys import IS_WIN
from picard.debug_opts import DebugOpt
from picard.log import (
_calculate_bounds,
name_filter,
@@ -161,6 +162,18 @@ class NameFilterTestRel(PicardTestCase):
self.assertTrue(name_filter(record))
self.assertEqual(record.name, '__init__/module')
def test_plugin_path_long(self):
DebugOpt.PLUGIN_FULLPATH.enabled = True
record = FakeRecord(name=None, pathname='/path1/path2/plugins/path3/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'plugins/path3/plugins/plugin')
def test_plugin_path_short(self):
DebugOpt.PLUGIN_FULLPATH.enabled = False
record = FakeRecord(name=None, pathname='/path1/path2/plugins/path3/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'plugins/plugin')
@unittest.skipIf(IS_WIN, "Posix test")
@patch('picard.log.picard_module_path', PurePosixPath('/picard'))
@@ -186,6 +199,18 @@ class NameFilterTestAbs(PicardTestCase):
with self.assertRaises(ValueError):
name_filter(record)
def test_plugin_path_long(self):
DebugOpt.PLUGIN_FULLPATH.enabled = True
record = FakeRecord(name=None, pathname='/path1/plugins/path2/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'path1/plugins/path2/plugins/plugin')
def test_plugin_path_short(self):
DebugOpt.PLUGIN_FULLPATH.enabled = False
record = FakeRecord(name=None, pathname='/path1/plugins/path2/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'path1/plugins/path2/plugins/plugin')
@unittest.skipIf(IS_WIN, "Posix test")
@patch('picard.log.picard_module_path', PurePosixPath('/path1/path2/')) # incorrect, but testing anyway
@@ -226,6 +251,18 @@ class NameFilterTestRelWin(PicardTestCase):
self.assertTrue(name_filter(record))
self.assertEqual(record.name, '__init__/module')
def test_plugin_path_long(self):
DebugOpt.PLUGIN_FULLPATH.enabled = True
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/path3/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'plugins/path3/plugins/plugin')
def test_plugin_path_short(self):
DebugOpt.PLUGIN_FULLPATH.enabled = False
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/path3/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'plugins/plugin')
@unittest.skipUnless(IS_WIN, "Windows test")
@patch('picard.log.picard_module_path', PureWindowsPath('C:/picard'))
@@ -251,6 +288,18 @@ class NameFilterTestAbsWin(PicardTestCase):
with self.assertRaises(ValueError):
name_filter(record)
def test_plugin_path_long(self):
DebugOpt.PLUGIN_FULLPATH.enabled = True
record = FakeRecord(name=None, pathname='C:/path1/plugins/path2/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'path1/plugins/path2/plugins/plugin')
def test_plugin_path_short(self):
DebugOpt.PLUGIN_FULLPATH.enabled = False
record = FakeRecord(name=None, pathname='C:/path1/plugins/path2/plugins/plugin.zip')
self.assertTrue(name_filter(record))
self.assertEqual(record.name, 'path1/plugins/path2/plugins/plugin')
@unittest.skipUnless(IS_WIN, "Windows test")
@patch('picard.log.picard_module_path', PureWindowsPath('C:/path1/path2/')) # incorrect, but testing anyway