Debian packaging for 0.99.3 on Fremantle
[panucci.git] / device.py
blob8e459811c4f96fdfa9ae359afd773c89c4622472
1 #!/usr/bin/python
3 import sys
4 import os
5 import ConfigParser
7 if len(sys.argv) != 2:
8 print >>sys.stderr, """
9 Usage: %s <device>
10 """ % sys.argv[0]
11 sys.exit(1)
13 appname, device = sys.argv
15 root = os.path.dirname(__file__)
16 devices = ConfigParser.ConfigParser()
17 devices.read([os.path.join(root, 'doc', 'devices.ini')])
19 if device not in devices.sections():
20 print 'Unknown device:', device
21 sys.exit(2)
23 files_to_update = ['panucci.conf', 'panucci-all.conf']
24 files_to_update = [os.path.join(root, 'data', x) for x in files_to_update]
26 def config_from_file(filename):
27 parser = ConfigParser.ConfigParser()
28 parser.read([filename])
29 return parser
31 parsers = map(config_from_file, files_to_update)
33 for key, value in devices.items(device):
34 for parser in parsers:
35 parser.set('options', key, value)
37 for parser, filename in zip(parsers, files_to_update):
38 parser.write(open(filename, 'w'))