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