git.cweiske.de
/
enigma2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cleanup eConsoleAppContainer code.. execute is now only possible to call with
[enigma2.git]
/
lib
/
python
/
Components
/
Network.py
diff --git
a/lib/python/Components/Network.py
b/lib/python/Components/Network.py
index 79ec1ed64f1831d3620b5ba14fed76968801a130..ecc547875883d0df162cf06a3a655ff61f9c0edf 100644
(file)
--- a/
lib/python/Components/Network.py
+++ b/
lib/python/Components/Network.py
@@
-2,15
+2,17
@@
from os import system, popen, path as os_path, listdir
from re import compile as re_compile
from socket import *
from enigma import eConsoleAppContainer
from re import compile as re_compile
from socket import *
from enigma import eConsoleAppContainer
+from Components.Console import Console
class Network:
def __init__(self):
self.ifaces = {}
class Network:
def __init__(self):
self.ifaces = {}
- self.configuredInterfaces = []
+ self.configuredInterfaces = []
self.nameservers = []
self.nameservers = []
- self.getInterfaces()
self.ethtool_bin = "/usr/sbin/ethtool"
self.container = eConsoleAppContainer()
self.ethtool_bin = "/usr/sbin/ethtool"
self.container = eConsoleAppContainer()
+ self.Console = Console()
+ self.getInterfaces()
def getInterfaces(self):
devicesPattern = re_compile('[a-z]+[0-9]+')
def getInterfaces(self):
devicesPattern = re_compile('[a-z]+[0-9]+')
@@
-23,7
+25,7
@@
class Network:
device = devicesPattern.search(line).group()
if device == 'wifi0':
continue
device = devicesPattern.search(line).group()
if device == 'wifi0':
continue
- self.
ifaces[device] = self.
getDataForInterface(device)
+ self.getDataForInterface(device)
# Show only UP Interfaces in E2
#if self.getAdapterAttribute(device, 'up') is False:
# del self.ifaces[device]
# Show only UP Interfaces in E2
#if self.getAdapterAttribute(device, 'up') is False:
# del self.ifaces[device]
@@
-31,7
+33,6
@@
class Network:
pass
#print "self.ifaces:", self.ifaces
pass
#print "self.ifaces:", self.ifaces
- self.loadNetworkConfig()
#self.writeNetworkConfig()
#print ord(' ')
#for line in result:
#self.writeNetworkConfig()
#print ord(' ')
#for line in result:
@@
-55,7
+56,11
@@
class Network:
return ip
def getDataForInterface(self, iface):
return ip
def getDataForInterface(self, iface):
- #ipRegexp = '[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}\.[0-9]{1,2,3}'
+ cmd = "ifconfig " + iface
+ self.Console.ePopen(cmd, self.ifconfigFinished, iface)
+
+ def ifconfigFinished(self, result, retval, iface):
+ data = { 'up': False, 'dhcp': False, 'preup' : False, 'postdown' : False }
ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
ipLinePattern = re_compile('inet addr:' + ipRegexp)
netmaskLinePattern = re_compile('Mask:' + ipRegexp)
ipRegexp = '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
ipLinePattern = re_compile('inet addr:' + ipRegexp)
netmaskLinePattern = re_compile('Mask:' + ipRegexp)
@@
-63,12
+68,8
@@
class Network:
ipPattern = re_compile(ipRegexp)
upPattern = re_compile('UP ')
macPattern = re_compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}')
ipPattern = re_compile(ipRegexp)
upPattern = re_compile('UP ')
macPattern = re_compile('[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{2}')
-
- fp = popen("ifconfig " + iface)
- result = fp.readlines()
- fp.close()
- data = { 'up': False, 'dhcp': False, 'preup' : False, 'postdown' : False }
- for line in result:
+
+ for line in result.splitlines():
ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, line))
netmask = self.regExpMatch(ipPattern, self.regExpMatch(netmaskLinePattern, line))
bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, line))
ip = self.regExpMatch(ipPattern, self.regExpMatch(ipLinePattern, line))
netmask = self.regExpMatch(ipPattern, self.regExpMatch(netmaskLinePattern, line))
bcast = self.regExpMatch(ipPattern, self.regExpMatch(bcastLinePattern, line))
@@
-88,20
+89,25
@@
class Network:
data['mac'] = mac
if not data.has_key('ip'):
data['dhcp'] = True
data['mac'] = mac
if not data.has_key('ip'):
data['dhcp'] = True
- data['ip'] = [
192, 168, 1, 2
]
- data['netmask'] = [
255, 255, 255
, 0]
- data['gateway'] = [
192, 168, 1, 1
]
+ data['ip'] = [
0, 0, 0, 0
]
+ data['netmask'] = [
0, 0, 0
, 0]
+ data['gateway'] = [
0, 0, 0, 0
]
- fp = popen("route -n | grep " + iface)
- result = fp.readlines()
- fp.close()
- for line in result:
+ cmd = "route -n | grep " + iface
+ self.Console.ePopen(cmd,self.routeFinished,[iface,data,ipPattern])
+
+ def routeFinished(self, result, retval, extra_args):
+ (iface, data, ipPattern) = extra_args
+
+ for line in result.splitlines():
print line[0:7]
if line[0:7] == "0.0.0.0":
gateway = self.regExpMatch(ipPattern, line[16:31])
if gateway is not None:
data['gateway'] = self.convertIP(gateway)
print line[0:7]
if line[0:7] == "0.0.0.0":
gateway = self.regExpMatch(ipPattern, line[16:31])
if gateway is not None:
data['gateway'] = self.convertIP(gateway)
- return data
+ self.ifaces[iface] = data
+ if len(self.Console.appContainers) == 0:
+ self.loadNetworkConfig()
def writeNetworkConfig(self):
self.configuredInterfaces = []
def writeNetworkConfig(self):
self.configuredInterfaces = []
@@
-163,14
+169,25
@@
class Network:
if (currif != ""):
if (split[0] == "address"):
ifaces[currif]["address"] = map(int, split[1].split('.'))
if (currif != ""):
if (split[0] == "address"):
ifaces[currif]["address"] = map(int, split[1].split('.'))
+ if self.ifaces[currif].has_key("ip"):
+ if self.ifaces[currif]["ip"] != ifaces[currif]["address"] and ifaces[currif]["dhcp"] == False:
+ self.ifaces[currif]["ip"] = map(int, split[1].split('.'))
if (split[0] == "netmask"):
ifaces[currif]["netmask"] = map(int, split[1].split('.'))
if (split[0] == "netmask"):
ifaces[currif]["netmask"] = map(int, split[1].split('.'))
+ if self.ifaces[currif].has_key("netmask"):
+ if self.ifaces[currif]["netmask"] != ifaces[currif]["netmask"] and ifaces[currif]["dhcp"] == False:
+ self.ifaces[currif]["netmask"] = map(int, split[1].split('.'))
if (split[0] == "gateway"):
ifaces[currif]["gateway"] = map(int, split[1].split('.'))
if (split[0] == "gateway"):
ifaces[currif]["gateway"] = map(int, split[1].split('.'))
+ if self.ifaces[currif].has_key("gateway"):
+ if self.ifaces[currif]["gateway"] != ifaces[currif]["gateway"] and ifaces[currif]["dhcp"] == False:
+ self.ifaces[currif]["gateway"] = map(int, split[1].split('.'))
if (split[0] == "pre-up"):
if (split[0] == "pre-up"):
- self.ifaces[currif]["preup"] = i
+ if self.ifaces[currif].has_key("preup"):
+ self.ifaces[currif]["preup"] = i
if (split[0] == "post-down"):
if (split[0] == "post-down"):
- self.ifaces[currif]["postdown"] = i
+ if self.ifaces[currif].has_key("postdown"):
+ self.ifaces[currif]["postdown"] = i
print "read interfaces:", ifaces
for ifacename, iface in ifaces.items():
print "read interfaces:", ifaces
for ifacename, iface in ifaces.items():
@@
-323,6
+340,12
@@
class Network:
self.container.appClosed.get().remove(self.cmdFinished)
self.container.dataAvail.get().remove(self.dataAvail)
self.container.appClosed.get().remove(self.cmdFinished)
self.container.dataAvail.get().remove(self.dataAvail)
+ def stopContainer(self):
+ self.container.kill()
+
+ def ContainerRunning(self):
+ return self.container.running()
+
def checkforInterface(self,iface):
if self.getAdapterAttribute(iface, 'up') is True:
return True
def checkforInterface(self,iface):
if self.getAdapterAttribute(iface, 'up') is True:
return True