Skip to content

Commit

Permalink
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'
  • Loading branch information
zas committed Sep 14, 2023
1 parent e2f1940 commit 0529595
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
Expand Up @@ -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):

Check warning

Code scanning / Prospector (reported by Codacy)

expected 1 blank line before a nested definition, found 0 (E306) Warning

expected 1 blank line before a nested definition, found 0 (E306)
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.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 0529595

Please sign in to comment.