remove debug
[enigma2.git] / lib / python / Screens / NetworkSetup.py
index 2e33ac3b02d519644fbee8e820b774a404a972f9..96a4c20c7fb952b0c28bc2c3140f24d462b75f40 100755 (executable)
@@ -184,6 +184,8 @@ class NetworkAdapterSelection(Screen,HelpableScreen):
                        self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
                if iNetwork.configuredNetworkAdapters.has_key('ath0') is True:
                        self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
+               if iNetwork.configuredNetworkAdapters.has_key('ra0') is True:
+                       self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.wlan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
                else:
                        self.session.openWithCallback(self.ErrorMessageClosed, MessageBox, self.lan_errortext, type = MessageBox.TYPE_INFO,timeout = 10)
 
@@ -192,6 +194,8 @@ class NetworkAdapterSelection(Screen,HelpableScreen):
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'wlan0')
                elif iNetwork.configuredNetworkAdapters.has_key('ath0') is True:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ath0')
+               elif iNetwork.configuredNetworkAdapters.has_key('ra0') is True:
+                       self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'ra0')
                else:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetupConfiguration, 'eth0')
 
@@ -426,7 +430,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                if self.iface in iNetwork.wlan_interfaces:
                        from Plugins.SystemPlugins.WirelessLan.Wlan import wpaSupplicant,Wlan
                        self.w = Wlan(self.iface)
-                       self.ws = wpaSupplicant()
+                       self.ws = wpaSupplicant(self.iface)
                        self.encryptionlist = []
                        self.encryptionlist.append(("WEP", _("WEP")))
                        self.encryptionlist.append(("WPA", _("WPA")))
@@ -502,6 +506,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                        self.list.append(getConfigListEntry(_('Gateway'), self.gatewayConfigEntry))
 
                        self.extended = None
+                       self.configStrings = None
                        for p in plugins.getPlugins(PluginDescriptor.WHERE_NETWORKSETUP):
                                callFnc = p.__call__["ifaceSupported"](self.iface)
                                if callFnc is not None:
@@ -509,8 +514,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                                self.extended = callFnc
                                                if p.__call__.has_key("configStrings"):
                                                        self.configStrings = p.__call__["configStrings"]
-                                               else:
-                                                       self.configStrings = None
+
                                                if config.plugins.wlan.essid.value == 'hidden...':
                                                        self.wlanSSID = getConfigListEntry(_("Network SSID"), config.plugins.wlan.essid)
                                                        self.list.append(self.wlanSSID)
@@ -576,7 +580,7 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                if (ret == True):               
                        num_configured_if = len(iNetwork.getConfiguredAdapters())
                        if num_configured_if >= 1:
-                               if num_configured_if == 1 and self.iface in iNetwork.getConfiguredAdapters():
+                               if self.iface in iNetwork.getConfiguredAdapters():      
                                        self.applyConfig(True)
                                else:
                                        self.session.openWithCallback(self.secondIfaceFoundCB, MessageBox, _("A second configured interface has been found.\n\nDo you want to disable the second network interface?"), default = True)
@@ -594,11 +598,15 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                                if interface == self.iface:
                                        continue
                                iNetwork.setAdapterAttribute(interface, "up", False)
-                               iNetwork.deactivateInterface(interface)
-                               self.applyConfig(True)
+                       iNetwork.deactivateInterface(configuredInterfaces,self.deactivateSecondInterfaceCB)
+
+       def deactivateSecondInterfaceCB(self, data):
+               if data is True:
+                       self.applyConfig(True)
 
        def applyConfig(self, ret = False):
                if (ret == True):
+                       self.applyConfigRef = None
                        iNetwork.setAdapterAttribute(self.iface, "up", self.activateInterfaceEntry.value)
                        iNetwork.setAdapterAttribute(self.iface, "dhcp", self.dhcpConfigEntry.value)
                        iNetwork.setAdapterAttribute(self.iface, "ip", self.ipConfigEntry.value)
@@ -610,14 +618,26 @@ class AdapterSetup(Screen, ConfigListScreen, HelpableScreen):
                        if self.extended is not None and self.configStrings is not None:
                                iNetwork.setAdapterAttribute(self.iface, "configStrings", self.configStrings(self.iface))
                                self.ws.writeConfig()
+
                        if self.activateInterfaceEntry.value is False:
-                               iNetwork.deactivateInterface(self.iface)
-                       iNetwork.writeNetworkConfig()
-                       iNetwork.restartNetwork(self.applyConfigDataAvail)
-                       self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
+                               iNetwork.deactivateInterface(self.iface,self.deactivateInterfaceCB)
+                               iNetwork.writeNetworkConfig()
+                               self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
+                       else:
+                               iNetwork.deactivateInterface(self.iface,self.activateInterfaceCB)
+                               iNetwork.writeNetworkConfig()
+                               self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait for activation of your network configuration..."), type = MessageBox.TYPE_INFO, enable_input = False)
                else:
                        self.keyCancel()
 
+       def deactivateInterfaceCB(self, data):
+               if data is True:
+                       self.applyConfigDataAvail(True)
+
+       def activateInterfaceCB(self, data):
+               if data is True:
+                       iNetwork.activateInterface(self.iface,self.applyConfigDataAvail)
+
        def applyConfigDataAvail(self, data):
                if data is True:
                        iNetwork.getInterfaces(self.getInterfacesDataAvail)
@@ -745,14 +765,22 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        if self.iface in iNetwork.wlan_interfaces:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
-                                       from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                                       from pythonwifi.iwlibs import Wireless
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
-                                       self.wlanresponse = ifobj.getStatistics()
-                                       if self.wlanresponse[0] != 19: # Wlan Interface found.
-                                               self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+                                       wlanresponse = None
+                                       try:
+                                               wlanresponse = ifobj.getAPaddr()
+                                       except IOError, (errno, strerror):
+                                               wlanresponse = (errno,strerror)
+                                       if wlanresponse:
+                                               if wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                                       self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup,self.iface)
+                                               else:
+                                                       # Display Wlan not available Message
+                                                       self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
@@ -765,28 +793,44 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                if self["menulist"].getCurrent()[1] == 'scanwlan':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanScan
-                               from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                               from pythonwifi.iwlibs import Wireless
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
-                               self.wlanresponse = ifobj.getStatistics()
-                               if self.wlanresponse[0] != 19:
-                                       self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
+                               wlanresponse = None
+                               try:
+                                       wlanresponse = ifobj.getAPaddr()
+                               except IOError, (errno, strerror):
+                                       wlanresponse = (errno,strerror)
+                               if wlanresponse:
+                                       if wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                               self.session.openWithCallback(self.WlanScanClosed, WlanScan, self.iface)
+                                       else:
+                                               # Display Wlan not available Message
+                                               self.showErrorMessage()
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
                if self["menulist"].getCurrent()[1] == 'wlanstatus':
                        try:
                                from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
-                               from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                               from pythonwifi.iwlibs import Wireless
                        except ImportError:
                                self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                        else:   
                                ifobj = Wireless(self.iface) # a Wireless NIC Object
-                               self.wlanresponse = ifobj.getStatistics()
-                               if self.wlanresponse[0] != 19:
-                                       self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                               wlanresponse = None
+                               try:
+                                       wlanresponse = ifobj.getAPaddr()
+                               except IOError, (errno, strerror):
+                                       wlanresponse = (errno,strerror)
+                               if wlanresponse:
+                                       if wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                               self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                       else:
+                                               # Display Wlan not available Message
+                                               self.showErrorMessage()
                                else:
                                        # Display Wlan not available Message
                                        self.showErrorMessage()
@@ -898,14 +942,22 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                        if ret[0] == 'ok' and (self.iface in iNetwork.wlan_interfaces) and iNetwork.getAdapterAttribute(self.iface, "up") is True:
                                try:
                                        from Plugins.SystemPlugins.WirelessLan.plugin import WlanStatus
-                                       from Plugins.SystemPlugins.WirelessLan.iwlibs import Wireless
+                                       from pythonwifi.iwlibs import Wireless
                                except ImportError:
                                        self.session.open(MessageBox, _("The wireless LAN plugin is not installed!\nPlease install it."), type = MessageBox.TYPE_INFO,timeout = 10 )
                                else:   
                                        ifobj = Wireless(self.iface) # a Wireless NIC Object
-                                       self.wlanresponse = ifobj.getStatistics()
-                                       if self.wlanresponse[0] != 19:
-                                               self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                       wlanresponse = None
+                                       try:
+                                               wlanresponse = ifobj.getAPaddr()
+                                       except IOError, (errno, strerror):
+                                               wlanresponse = (errno,strerror)
+                                       if wlanresponse:
+                                               if wlanresponse[0] not in (19,95): # 19 = 'No such device', 95 = 'Operation not supported'
+                                                       self.session.openWithCallback(self.WlanStatusClosed, WlanStatus,self.iface)
+                                               else:
+                                                       # Display Wlan not available Message
+                                                       self.showErrorMessage()
                                        else:
                                                # Display Wlan not available Message
                                                self.showErrorMessage()
@@ -916,7 +968,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
 
        def WlanStatusClosed(self, *ret):
                if ret is not None and len(ret):
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
 
@@ -924,7 +976,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
                if ret[0] is not None:
                        self.session.openWithCallback(self.AdapterSetupClosed, AdapterSetup, self.iface,ret[0],ret[1])
                else:
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        iStatus.stopWlanConsole()
                        self.updateStatusbar()
                        
@@ -967,6 +1019,7 @@ class AdapterSetupConfiguration(Screen, HelpableScreen):
        def cleanup(self):
                iNetwork.stopLinkStateConsole()
                iNetwork.stopDeactivateInterfaceConsole()
+               iNetwork.stopActivateInterfaceConsole()
                iNetwork.stopPingConsole()
                try:
                        from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
@@ -1335,7 +1388,7 @@ class NetworkAdapterTest(Screen):
        def getLinkState(self,iface):
                if iface in iNetwork.wlan_interfaces:
                        try:
-                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                               from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                        except:
                                        self["Network"].setForegroundColorNum(1)
                                        self["Network"].setText(_("disconnected"))
@@ -1348,7 +1401,7 @@ class NetworkAdapterTest(Screen):
 
        def LinkStatedataAvail(self,data):
                self.output = data.strip()
-               result = self.output.split('\n')
+               result = self.output.splitlines()
                pattern = re_compile("Link detected: yes")
                for item in result:
                        if re_search(pattern, item):
@@ -1417,7 +1470,7 @@ class NetworkAdapterTest(Screen):
                iNetwork.stopLinkStateConsole()
                iNetwork.stopDNSConsole()
                try:
-                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus,Status
+                       from Plugins.SystemPlugins.WirelessLan.Wlan import iStatus
                except ImportError:
                        pass
                else: