3 Dead simple script to query the NeuroDebian dev config (or any other Python config file)
8 from ConfigParser import SafeConfigParser
9 from optparse import OptionParser
11 __prog__ = os.path.basename(sys.argv[0])
14 if __name__ == '__main__':
15 parser = OptionParser(
16 usage="%s [OPTIONS] [section] [field]\n" % __prog__ + __doc__,
17 version="%prog " + __version__)
20 '-f', '--config-file', default="/etc/neurodebian/neurodebian.cfg",
21 help="name of the config file")
24 '-F', '--value-separator', default="=",
25 help="string to separate key from value")
27 opts, argv = parser.parse_args()
29 if not os.path.exists(opts.config_file):
30 sys.stderr.write("ERROR: File %s does not exist\n" % opts.config_file)
33 cfg = SafeConfigParser()
34 cfg.read(opts.config_file)
36 print cfg.get(argv[0], argv[1])
38 # Print values of the section, =-separate key from value
39 print '\n'.join([opts.value_separator.join(x)
40 for x in cfg.items(argv[0])])
43 print '\n'.join(cfg.sections())