add digitCount to init
[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 setMACAddress(self, mac):
22                 os.system("echo ifconfig eth0 %02x:%02x:%02x:%02x:%02x:%02x" % (mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]))
23                 
24 def InitNetwork():
25         config.network = ConfigSubsection()
26         config.network.ip = configElement("config.network.ip", configSequence, [192,168,1,45], (("."), 3))
27         config.network.gateway = configElement("config.network.gateway", configSequence, [192,168,1,3], (("."), 3))
28         config.network.dns = configElement("config.network.dns", configSequence, [192,168,1,3], (("."), 3))
29         config.network.mac = configElement("config.network.mac", configSequence, [00,11,22,33,44,55], ((":"), 2))
30
31         iNetwork = Network()
32
33         def setIPAddress(configElement):
34                 iNetwork.setIPAddress(configElement.value)
35
36         def setIPGateway(configElement):
37                 iNetwork.setIPGateway(configElement.value)
38                 
39         def setIPNameserver(configElement):
40                 iNetwork.setIPNameserver(configElement.value)
41
42         def setMACAddress(configElement):
43                 iNetwork.setMACAddress(configElement.value)
44
45         # this will call the "setup-val" initial
46         config.network.ip.addNotifier(setIPAddress)
47         config.network.gateway.addNotifier(setIPGateway)
48         config.network.dns.addNotifier(setIPNameserver)
49         config.network.mac.addNotifier(setMACAddress)