2012-05-21 15:12:37 +04: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 10:51:19 +03:00
|
|
|
import sys
|
2020-03-18 18:07:24 +03:00
|
|
|
|
|
|
|
from configparser import (
|
|
|
|
ConfigParser,
|
|
|
|
NoOptionError,
|
|
|
|
NoSectionError,
|
|
|
|
)
|
2007-07-02 22:20:24 +04:00
|
|
|
|
|
|
|
try:
|
2020-03-18 18:07:24 +03:00
|
|
|
(filename, section, key) = sys.argv[1:]
|
2007-07-02 22:20:24 +04:00
|
|
|
except ValueError:
|
2020-03-18 18:07:24 +03:00
|
|
|
print("Usage: printconfigsetting.py <filename> <section> <setting>")
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2020-03-18 18:07:24 +03:00
|
|
|
cfg = ConfigParser()
|
|
|
|
cfg.read(filename)
|
2007-07-02 22:20:24 +04:00
|
|
|
|
|
|
|
try:
|
2020-03-18 18:07:24 +03:00
|
|
|
print(cfg.get(section, key))
|
|
|
|
except NoOptionError:
|
|
|
|
print("Key %s not found." % key, file=sys.stderr)
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|
2020-03-18 18:07:24 +03:00
|
|
|
except NoSectionError:
|
|
|
|
print("Section [%s] not found." % section, file=sys.stderr)
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|