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