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 6250d987c6
commit 57f7635242

View File

@ -2,7 +2,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # 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/. # 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: try:
(file, section, key) = sys.argv[1:] (file, section, key) = sys.argv[1:]
@ -10,7 +13,10 @@ except ValueError:
print "Usage: printconfigsetting.py <file> <section> <setting>" print "Usage: printconfigsetting.py <file> <section> <setting>"
sys.exit(1) 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: try:
s = c[section] s = c[section]