From 0529595cda5f4d1d50a6eb5dbe7355366f587582 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Thu, 14 Sep 2023 20:16:31 +0200 Subject: [PATCH] Add a command-line option to enable audit, using Python 3.8 sys.addaudithook() That's a debugging feature. Try '--audit os' or '--audit all' --- picard/tagger.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/picard/tagger.py b/picard/tagger.py index 5c1f1dcf38e..8ecb834c603 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -256,6 +256,33 @@ def __init__(self, picard_args, localedir, autoupdate, pipe_handler=None): if picard_args.debug or "PICARD_DEBUG" in os.environ: self.set_log_level(logging.DEBUG) + if sys.version_info[:3] > (3,8): + if picard_args.audit: + if picard_args.audit == 'all': + def event_match(event): + return True + else: + events = set(tuple(e.split('.')) for e in picard_args.audit.split(',')) + print(events) + def event_match(event): + ev = tuple(event.split('.')) + ev_len = len(ev) + for e in events: + e_len = len(e) + if e_len > ev_len: + continue + for i in range(e_len): + if e[i] != ev[i]: + return False + return True + return False + + def audit(event, args): + if event_match(event): + print(f'audit: {event} with args={args}') + + sys.addaudithook(audit) + # Main thread pool used for most background tasks self.thread_pool = QtCore.QThreadPool(self) # Two threads are needed for the pipe handler and command processing. @@ -1437,6 +1464,11 @@ def process_picard_args(): parser.add_argument("-display", nargs=1, help=argparse.SUPPRESS) # Picard specific arguments + if sys.version_info[:3] > (3,8): + parser.add_argument("-a", "--audit", action='store', + default=None, + help="audit events passed as a comma-separated list, prefixes supported, " + "use all to match any (see https://docs.python.org/3/library/audit_events.html#audit-events)") parser.add_argument("-c", "--config-file", action='store', default=None, help="location of the configuration file")