1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5import sys 6 7from configparser import ( 8 ConfigParser, 9 NoOptionError, 10 NoSectionError, 11) 12 13try: 14 (filename, section, key) = sys.argv[1:] 15except ValueError: 16 print("Usage: printconfigsetting.py <filename> <section> <setting>") 17 sys.exit(1) 18 19cfg = ConfigParser() 20cfg.read(filename) 21 22try: 23 print(cfg.get(section, key)) 24except NoOptionError: 25 print("Key %s not found." % key, file=sys.stderr) 26 sys.exit(1) 27except NoSectionError: 28 print("Section [%s] not found." % section, file=sys.stderr) 29 sys.exit(1) 30