xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/dnstap/ydump.py (revision 8ecbf5f02b752fcb7debe1a8fab1dc82602bc760)
1############################################################################
2# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3#
4# This Source Code Form is subject to the terms of the Mozilla Public
5# License, v. 2.0. If a copy of the MPL was not distributed with this
6# file, You can obtain one at http://mozilla.org/MPL/2.0/.
7#
8# See the COPYRIGHT file distributed with this work for additional
9# information regarding copyright ownership.
10############################################################################
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