xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/dnstap/ydump.py (revision f281902de12281841521aa31ef834ad944d725e2)
1# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2#
3# SPDX-License-Identifier: MPL-2.0
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0.  If a copy of the MPL was not distributed with this
7# file, you can obtain one at https://mozilla.org/MPL/2.0/.
8#
9# See the COPYRIGHT file distributed with this work for additional
10# information regarding copyright ownership.
11
12import sys
13
14try:
15    import yaml
16except (ModuleNotFoundError, ImportError):
17    print("No python yaml module, skipping")
18    sys.exit(1)
19
20import subprocess
21import pprint
22
23DNSTAP_READ = sys.argv[1]
24DATAFILE = sys.argv[2]
25ARGS = [DNSTAP_READ, "-y", DATAFILE]
26
27with subprocess.Popen(ARGS, stdout=subprocess.PIPE) as f:
28    for y in yaml.load_all(f.stdout, Loader=yaml.SafeLoader):
29        pprint.pprint(y)
30