2012-05-21 11:12:37 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2015-10-06 07:51:19 +00:00
|
|
|
import sys
|
2020-03-18 15:07:24 +00:00
|
|
|
|
|
|
|
from configparser import (
|
|
|
|
ConfigParser,
|
|
|
|
NoOptionError,
|
|
|
|
NoSectionError,
|
|
|
|
)
|
2007-07-02 18:20:24 +00:00
|
|
|
|
|
|
|
try:
|
2020-03-18 15:07:24 +00:00
|
|
|
(filename, section, key) = sys.argv[1:]
|
2007-07-02 18:20:24 +00:00
|
|
|
except ValueError:
|
2020-03-18 15:07:24 +00:00
|
|
|
print("Usage: printconfigsetting.py <filename> <section> <setting>")
|
2007-07-02 18:20:24 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2020-03-18 15:07:24 +00:00
|
|
|
cfg = ConfigParser()
|
|
|
|
cfg.read(filename)
|
2007-07-02 18:20:24 +00:00
|
|
|
|
|
|
|
try:
|
2020-03-18 15:07:24 +00:00
|
|
|
print(cfg.get(section, key))
|
|
|
|
except NoOptionError:
|
|
|
|
print("Key %s not found." % key, file=sys.stderr)
|
2007-07-02 18:20:24 +00:00
|
|
|
sys.exit(1)
|
2020-03-18 15:07:24 +00:00
|
|
|
except NoSectionError:
|
|
|
|
print("Section [%s] not found." % section, file=sys.stderr)
|
2007-07-02 18:20:24 +00:00
|
|
|
sys.exit(1)
|