printconfigsetting.py 767 B

1234567891011121314151617181920212223242526272829303132
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import configobj
  5. import sys
  6. import re
  7. from StringIO import StringIO
  8. try:
  9. (file, section, key) = sys.argv[1:]
  10. except ValueError:
  11. print "Usage: printconfigsetting.py <file> <section> <setting>"
  12. sys.exit(1)
  13. with open(file) as fh:
  14. content = re.sub('^\s*;', '#', fh.read(), flags=re.M)
  15. c = configobj.ConfigObj(StringIO(content))
  16. try:
  17. s = c[section]
  18. except KeyError:
  19. print >>sys.stderr, "Section [%s] not found." % section
  20. sys.exit(1)
  21. try:
  22. print s[key]
  23. except KeyError:
  24. print >>sys.stderr, "Key %s not found." % key
  25. sys.exit(1)