Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command-line option to enable audit, using Python 3.8 sys.addau…
Browse files Browse the repository at this point in the history
…dithook()

That's a debugging feature.

Try '--audit os' or '--audit all'
zas committed Sep 14, 2023
1 parent e2f1940 commit b296702
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions picard/tagger.py
Original file line number Diff line number Diff line change
@@ -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(','))

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")

0 comments on commit b296702

Please sign in to comment.