xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/digdelv/yamlget.py (revision 154bfe8e089c1a0a4e9ed8414f08d3da90949162)
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
16# flake8: noqa: E722
17# pylint: disable=bare-except
18except:
19    print("No python yaml module, skipping")
20    sys.exit(1)
21
22with open(sys.argv[1], "r") as f:
23    for item in yaml.safe_load_all(f):
24        for key in sys.argv[2:]:
25            try:
26                key = int(key)
27            except ValueError:
28                pass
29
30            try:
31                item = item[key]
32            except KeyError:
33                print('Key "' + key + '" not found.')
34                sys.exit(1)
35
36        print(item)
37