Skip to content

Commit

Permalink
Introduce DebugOpt.PLUGIN_FULLPATH and shorten plugin paths in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zas committed Apr 12, 2024
1 parent 735aaec commit f6a0a68
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions picard/debug_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ def get_registry(cls):

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')
7 changes: 7 additions & 0 deletions picard/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
FROZEN_TEMP_PATH,
IS_FROZEN,
)
from picard.debug_opts import DebugOpt


# Get the absolute path for the picard module
Expand Down Expand Up @@ -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]
Expand Down
49 changes: 49 additions & 0 deletions test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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,
Expand Down Expand Up @@ -161,6 +162,18 @@ def test_5(self):
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'))
Expand All @@ -186,6 +199,18 @@ def test_4(self):
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
Expand Down Expand Up @@ -226,6 +251,18 @@ def test_5(self):
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'))
Expand All @@ -251,6 +288,18 @@ def test_4(self):
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
Expand Down

0 comments on commit f6a0a68

Please sign in to comment.