added device.py script
[panucci.git] / device.py
blobe4bcea1d0700f696e3c86947149448d69f123c08
1 #!/usr/bin/env python
3 # Usage: device.py <device name>
5 import sys
6 import os
8 bin_dir = os.path.dirname(sys.argv[0])
9 _device = sys.argv[1]
11 _file = open(bin_dir + "doc/devices.txt")
12 _str = _file.read()
13 _file.close()
14 _list = _str.splitlines()
16 check_list = []
17 _check = False
18 for i in _list:
19 if not _check:
20 if i.strip(":") == _device:
21 _check = True
22 else:
23 if i.startswith(" "):
24 check_list.append(i.strip())
25 else:
26 break
28 _file = open(bin_dir + "data/panucci.conf")
29 _str = _file.read()
30 _file.close()
31 panucci_conf = _str.splitlines()
33 _file = open(bin_dir + "data/panucci-all.conf")
34 _str = _file.read()
35 _file.close()
36 panucci_all_conf = _str.splitlines()
38 for i in range(len(panucci_conf)):
39 _option = panucci_conf[i].split("=")[0].strip()
40 for j in check_list:
41 new_option = j.split("=")[0].strip()
42 if new_option == _option:
43 panucci_conf[i] = j
45 for i in range(len(panucci_all_conf)):
46 _option = panucci_all_conf[i].split("=")[0].strip()
47 for j in check_list:
48 new_option = j.split("=")[0].strip()
49 if new_option == _option:
50 panucci_all_conf[i] = j
52 _file = open(bin_dir + "data/panucci.conf.new", "w")
53 for i in panucci_conf:
54 _file.write(i + "\n")
55 _file.close()
57 _file = open(bin_dir + "data/panucci-all.conf.new", "w")
58 for i in panucci_all_conf:
59 _file.write(i + "\n")
60 _file.close()