network setup stuff
[vuplus_dvbapp] / lib / python / Components / Network.py
1 from config import *
2
3 import os
4
5 class Network:
6         def __init__(self):
7                 pass
8                 
9         def setIPAddress(self, ip):
10                 print ip
11                 #os.system("echo ifconfig eth0 %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
12
13         def setIPGateway(self, ip):
14                 os.system("echo route add default gw %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
15
16         def setIPNameserver(self, ip):
17                 resolvconf = file('/etc/resolv.conf', 'w')
18                 resolvconf.write("nameserver %d.%d.%d.%d" % (ip[0], ip[1], ip[2], ip[3]))
19                 resolvconf.close()
20                 
21 def InitNetwork():
22         config.network = ConfigSubsection();
23         config.network.ip = configElement("config.network.ip", configSequence, [192,168,1,45], (".") );
24         config.network.gateway = configElement("config.network.gateway", configSequence, [192,168,1,3], (".") );
25         config.network.dns = configElement("config.network.dns", configSequence, [192,168,1,3], (".") );
26
27         iNetwork = Network()
28
29         def setIPAddress(configElement):
30                 iNetwork.setIPAddress(configElement.value);
31
32         def setIPGateway(configElement):
33                 iNetwork.setIPGateway(configElement.value);
34                 
35         def setIPNameserver(configElement):
36                 iNetwork.setIPNameserver(configElement.value);
37
38
39         # this will call the "setup-val" initial
40         config.network.ip.addNotifier(setIPAddress);
41         config.network.gateway.addNotifier(setIPGateway);
42         config.network.dns.addNotifier(setIPNameserver);