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