[PATCH 6/7] Network TUI: show the same status as in gui.

Radek Vykydal rvykydal at redhat.com
Fri Sep 13 13:32:20 UTC 2013


Not only for ethernet devices. Consolidate gui and tui functions.
---
 pyanaconda/network.py               | 70 +++++++++++++++++++++++++++++++++++++
 pyanaconda/ui/gui/spokes/network.py | 55 +----------------------------
 pyanaconda/ui/tui/spokes/network.py | 27 +-------------
 3 files changed, 72 insertions(+), 80 deletions(-)

diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 9c526ad..67cae66 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -44,6 +44,8 @@ from pyanaconda import constants
 from pyanaconda.flags import flags, can_touch_runtime_system
 from pyanaconda.i18n import _
 
+from gi.repository import NetworkManager
+
 import logging
 log = logging.getLogger("anaconda")
 
@@ -1028,3 +1030,71 @@ def wait_for_connectivity(timeout=constants.NETWORK_CONNECTION_TIMEOUT):
     # so we need to release it
     network_connected_condition.release()
     return connected
+
+def status_message():
+    """ A short string describing which devices are connected. """
+
+    msg = _("Unknown")
+
+    state = nm.nm_state()
+    if state == NetworkManager.State.CONNECTING:
+        msg = _("Connecting...")
+    elif state == NetworkManager.State.DISCONNECTING:
+        msg = _("Disconnecting...")
+    else:
+        active_devs = nm.nm_activated_devices()
+        if active_devs:
+
+            slaves = {}
+            ssids = {}
+            nonslaves = []
+
+            # first find slaves and wireless aps
+            for devname in active_devs:
+                master = nm.nm_device_setting_value(devname, "connection", "master")
+                if master:
+                    if master in slaves:
+                        slaves[master].append(devname)
+                    else:
+                        slaves[master] = [devname]
+                else:
+                    nonslaves.append(devname)
+                if nm.nm_device_type_is_wifi(devname):
+                    ssids[devname] = nm.nm_device_active_ssid(devname) or ""
+
+            if len(nonslaves) == 1:
+                if nm.nm_device_type_is_ethernet(devname):
+                    msg = _("Wired (%(interface_name)s) connected") \
+                          % {"interface_name": devname}
+                elif nm.nm_device_type_is_wifi(devname):
+                    msg = _("Wireless connected to %(access_point)s") \
+                          % {"access_point" : ssids[devname]}
+                elif nm.nm_device_type_is_bond(devname):
+                    msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") \
+                          % {"interface_name": devname, \
+                             "list_of_slaves": ",".join(slaves[devname])}
+                elif nm.nm_device_type_is_vlan(devname):
+                    parent = nm.nm_device_setting_value(devname, "vlan", "parent")
+                    vlanid = nm.nm_device_setting_value(devname, "vlan", "id")
+                    msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") \
+                          % {"interface_name": devname, "parent_device": parent, "vlanid": vlanid}
+            elif len(nonslaves) > 1:
+                devlist = []
+                for devname in nonslaves:
+                    if nm.nm_device_type_is_ethernet(devname):
+                        devlist.append("%s" % devname)
+                    elif nm.nm_device_type_is_wifi(devname):
+                        devlist.append("%s" % ssids[devname])
+                    elif nm.nm_device_type_is_bond(devname):
+                        devlist.append("%s (%s)" % (devname, ",".join(slaves[devname])))
+                    elif nm.nm_device_type_is_vlan(devname):
+                        devlist.append("%s" % devname)
+                msg = _("Connected: %(list_of_interface_names)s") \
+                      % {"list_of_interface_names": ", ".join(devlist)}
+        else:
+            msg = _("Not connected")
+
+    if not nm.nm_devices():
+        msg = _("No network devices available")
+
+    return msg
diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py
index 372602e..33d0a15 100644
--- a/pyanaconda/ui/gui/spokes/network.py
+++ b/pyanaconda/ui/gui/spokes/network.py
@@ -1290,60 +1290,7 @@ class NetworkSpoke(FirstbootSpokeMixIn, NormalSpoke):
     @property
     def status(self):
         """ A short string describing which devices are connected. """
-        msg = _("Unknown")
-
-        state = self.network_control_box.client.get_state()
-        if state == NetworkManager.State.CONNECTING:
-            msg = _("Connecting...")
-        elif state == NetworkManager.State.DISCONNECTING:
-            msg = _("Disconnecting...")
-        else:
-            ac = self.network_control_box.activated_connections()
-            if ac:
-                # Don't show bond slaves
-                slaves = []
-                for name, ty, info in ac:
-                    if ty == NetworkManager.DeviceType.BOND:
-                        slaves.extend(info)
-                if slaves:
-                    ac = [(name, ty, info)
-                          for name, ty, info in ac
-                          if name not in slaves]
-
-                if len(ac) == 1:
-                    name, ty, info = ac[0]
-                    if ty == NetworkManager.DeviceType.ETHERNET:
-                        msg = _("Wired (%(interface_name)s) connected") \
-                              % {"interface_name": name}
-                    elif ty == NetworkManager.DeviceType.WIFI:
-                        msg = _("Wireless connected to %(access_point)s") \
-                              % {"access_point" : info}
-                    elif ty == NetworkManager.DeviceType.BOND:
-                        msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") \
-                              % {"interface_name": name, "list_of_slaves": ",".join(info)}
-                    if ty == NetworkManager.DeviceType.VLAN:
-                        msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") \
-                              % {"interface_name": name, "parent_device": info[0], "vlanid": info[1]}
-                else:
-                    devlist = []
-                    for name, ty, info in ac:
-                        if ty == NetworkManager.DeviceType.ETHERNET:
-                            devlist.append("%s" % name)
-                        elif ty == NetworkManager.DeviceType.WIFI:
-                            devlist.append("%s" % info)
-                        elif ty == NetworkManager.DeviceType.BOND:
-                            devlist.append("%s (%s)" % (name, ",".join(info)))
-                        if ty == NetworkManager.DeviceType.VLAN:
-                            devlist.append("%s" % name)
-                    msg = _("Connected: %(list_of_interface_names)s") \
-                          % {"list_of_interface_names": ", ".join(devlist)}
-            else:
-                msg = _("Not connected")
-
-        if not self.network_control_box.listed_devices:
-            msg = _("No network devices available")
-
-        return msg
+        return network.status_message()
 
     def initialize(self):
         register_secret_agent(self)
diff --git a/pyanaconda/ui/tui/spokes/network.py b/pyanaconda/ui/tui/spokes/network.py
index 95432bc..eb6895a 100644
--- a/pyanaconda/ui/tui/spokes/network.py
+++ b/pyanaconda/ui/tui/spokes/network.py
@@ -72,32 +72,7 @@ class NetworkSpoke(EditTUISpoke):
     @property
     def status(self):
         """ Short msg telling what devices are active. """
-        msg = _("Unknown")
-
-        state = nm_state()
-        if state == NetworkManager.State.CONNECTING:
-            msg = _("Connecting...")
-        elif state == NetworkManager.State.DISCONNECTING:
-            msg = _("Disconnecting...")
-        else:
-            activated_devs = nm_activated_devices()
-            if not activated_devs:
-                msg = _("Not connected")
-            elif len(activated_devs) == 1:
-                if nm_device_type_is_ethernet(activated_devs[0]):
-                    msg = _("Wired %s connected" % activated_devs[0])
-            else:
-                devlist = []
-                for dev in activated_devs:
-                    if nm_device_type_is_ethernet(dev):
-                        devlist.append("%s" % dev)
-                msg = _("Connected: %(list_of_interface_names)s") \
-                      % {"list_of_interface_names": ", ".join(devlist)}
-
-        if not nm_devices():
-            msg = _("No network devices available")
-
-        return msg
+        return network.status_message()
 
     def _summary_text(self):
         """Devices cofiguration shown to user."""
-- 
1.7.11.7



More information about the anaconda-patches mailing list