forked from xerxes2/panucci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.py
39 lines (28 loc) · 923 Bytes
/
device.py
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
34
35
36
37
38
#!/usr/bin/python
import sys
import os
import ConfigParser
if len(sys.argv) != 2:
print >>sys.stderr, """
Usage: %s <device>
""" % sys.argv[0]
sys.exit(1)
appname, device = sys.argv
root = os.path.dirname(__file__)
devices = ConfigParser.ConfigParser()
devices.read([os.path.join(root, 'doc', 'devices.ini')])
if device not in devices.sections():
print 'Unknown device:', device
sys.exit(2)
files_to_update = ['panucci.conf', 'default.conf']
files_to_update = [os.path.join(root, 'data', x) for x in files_to_update]
def config_from_file(filename):
parser = ConfigParser.ConfigParser()
parser.read([filename])
return parser
parsers = map(config_from_file, files_to_update)
for key, value in devices.items(device):
for parser in parsers:
parser.set('options', key, value)
for parser, filename in zip(parsers, files_to_update):
parser.write(open(filename, 'w'))