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 configobj
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
from StringIO import StringIO
|
2007-07-02 22:20:24 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
(file, section, key) = sys.argv[1:]
|
|
|
|
except ValueError:
|
2018-05-22 16:22:46 +03:00
|
|
|
print("Usage: printconfigsetting.py <file> <section> <setting>")
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
2015-10-06 10:51:19 +03:00
|
|
|
with open(file) as fh:
|
|
|
|
content = re.sub('^\s*;', '#', fh.read(), flags=re.M)
|
|
|
|
|
|
|
|
c = configobj.ConfigObj(StringIO(content))
|
2007-07-02 22:20:24 +04:00
|
|
|
|
|
|
|
try:
|
|
|
|
s = c[section]
|
|
|
|
except KeyError:
|
2013-03-02 22:31:19 +04:00
|
|
|
print >>sys.stderr, "Section [%s] not found." % section
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
2018-05-22 16:22:46 +03:00
|
|
|
print(s[key])
|
2007-07-02 22:20:24 +04:00
|
|
|
except KeyError:
|
2013-03-02 22:31:19 +04:00
|
|
|
print >>sys.stderr, "Key %s not found." % key
|
2007-07-02 22:20:24 +04:00
|
|
|
sys.exit(1)
|