Bug 957911 - Work around the lack of support for semi-colon comments in python/configobj. r=gps

This commit is contained in:
Mike Hommey 2015-10-06 16:51:19 +09:00
parent e948cf7002
commit cb814d9fb5

View File

@ -2,7 +2,10 @@
# 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/.
import configobj, sys
import configobj
import sys
import re
from StringIO import StringIO
try:
(file, section, key) = sys.argv[1:]
@ -10,7 +13,10 @@ except ValueError:
print "Usage: printconfigsetting.py <file> <section> <setting>"
sys.exit(1)
c = configobj.ConfigObj(file)
with open(file) as fh:
content = re.sub('^\s*;', '#', fh.read(), flags=re.M)
c = configobj.ConfigObj(StringIO(content))
try:
s = c[section]