forked from dtmateojr/dtmrepo
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadconf
More file actions
executable file
·34 lines (24 loc) · 708 Bytes
/
readconf
File metadata and controls
executable file
·34 lines (24 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import ConfigParser
import sys
def usage():
sys.stderr.write('Usage: %s <config file> <section>\n\n' % sys.argv[0].split('/')[-1])
sys.exit(1)
def read_conf(config, section):
parser = ConfigParser.SafeConfigParser()
try:
parser.read(config)
except:
sys.stderr.write('Error reading %s.\n' % config)
sys.exit(1)
try:
opts = parser.items(section)
except:
sys.stderr.write('Missing section %s in %s.\n' % (section,config))
sys.exit(1)
for opt,val in opts:
print '%s=%s' % (opt, val)
if __name__ == '__main__':
if len(sys.argv) < 3:
usage()
read_conf(sys.argv[1], sys.argv[2])