Bug 957911 - Work around the lack of support for semi-colon comments in python/configobj. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 06 Oct 2015 16:51:19 +0900
changeset 266805 211d62ae4c2710b6a46a4bd11251b77fca7b9ef8
parent 266804 61235b7b074827d2f6d5070bd761e713bac655f1
child 266806 8d60143991365b92b3ac8b94108ec612f1bd2144
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs957911
milestone44.0a1
Bug 957911 - Work around the lack of support for semi-colon comments in python/configobj. r=gps
config/printconfigsetting.py
--- a/config/printconfigsetting.py
+++ b/config/printconfigsetting.py
@@ -1,21 +1,27 @@
 # 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/.
 
-import configobj, sys
+import configobj
+import sys
+import re
+from StringIO import StringIO
 
 try:
     (file, section, key) = sys.argv[1:]
 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]
 except KeyError:
     print >>sys.stderr, "Section [%s] not found." % section
     sys.exit(1)
 
 try: