[PATCH f20-branch] network gui spoke: use GDBus to obtain list of settings (#1018467)

Radek Vykydal rvykydal at redhat.com
Tue Oct 15 13:06:26 UTC 2013


On 10/15/2013 02:12 AM, Brian C. Lane wrote:
> On Mon, Oct 14, 2013 at 05:00:08PM +0200, Radek Vykydal wrote:
>> Another step in moving to GDBus.
>> libnm-glib (NMRemoteSettings.list_connections()) returns empty list
>> when called for the first time.
>> ---
>>   pyanaconda/installclasses/fedora.py |   2 +-
>>   pyanaconda/network.py               |   6 +-
>>   pyanaconda/nm.py                    |  47 ++++++++++++--
>>   pyanaconda/ui/gui/spokes/network.py | 118 +++++++++++++-----------------------
>>   4 files changed, 86 insertions(+), 87 deletions(-)
>> +def nm_ap_setting_value(ssid, key1, key2):
>> +    """Return value of ap's setting specified by key1 and key2.
>> +
>> +       :param name: name of ap (ssid)
>> +       :type name: str
> Looks like you changed it to ssid, not name.

Yep.

>
>> +       :param key1: first-level key of setting (eg "connection")
>> +       :type key1: str
>> +       :param key2: second-level key of setting (eg "uuid")
>> +       :type key2: str
>> +       :return: value of setting or None if the setting was not found
>> +                which means it does not exist or default value is used
>> +                by NM
>> +       :rtype: unpacked GDBus variant or None
>> +       :raise SettingsNotFoundError: if settings were not found
>> +                                           (eg for "wlan0")
>> +    """
>> +    settings_path = _settings_for_ap(ssid)
>> +    if not settings_path:
>> +        raise SettingsNotFoundError(ssid)
>> +    proxy = _get_proxy(object_path=settings_path, interface_name="org.freedesktop.NetworkManager.Settings.Connection")
>> +    args = None
>> +    settings = proxy.call_sync("GetSettings",
>> +                               args,
>> +                               Gio.DBusCallFlags.NONE,
>> +                               DEFAULT_DBUS_TIMEOUT,
>> +                               None)
>> +    settings = settings.unpack()[0]
>> +    try:
>> +        value = settings[key1][key2]
>> +    except KeyError:
>> +        #raise SettingNotFoundError(key1, key2)
>> +        value = None
> It isn't actually raising it :)

Yes, only SettingsNotFoundError can be raised, but I'll remove
the commented line.
>> +    return value
>> +
>> +
>>   def nm_activate_device_connection(dev_name, con_uuid):
>>       """Activate device with specified connection.
>> @@ -958,7 +993,7 @@ def test():
>>       if wireless_device:
>>           try:
>>               nm_update_settings_of_device(wireless_device, [[key1, key2, new_value, None]])
>> -        except DeviceSettingsNotFoundError as e:
>> +        except SettingsNotFoundError as e:
>>               print "%s" % e
> Not new, but we shouldn't be printing anything.

It used to be __main__ testing code which has been moved into test().
I'll take care of the test() some time.

>
>>   class CellRendererSignal(Gtk.CellRendererPixbuf):
>> @@ -386,11 +381,14 @@ class NetworkControlBox(object):
>>   
>>           log.info("network: access point changed: %s", ssid_target)
>>   
>> -        con = self.find_connection_for_device(device, ssid_target)
>> -        if con:
>> -            self.client.activate_connection(con, device,
>> -                                            None, None, None)
>> -        else:
>> +        try:
>> +            uuid = nm.nm_ap_setting_value(ssid_target, "connection", "uuid")
>> +            try:
>> +                nm.nm_activate_device_connection(device.get_iface(), uuid)
>> +            except nm.UnmanagedDeviceError as e:
>> +                log.debug("network: on_wireless_ap_changed: %s", e)
>> +        except nm.SettingsNotFoundError as e:
>> +            log.debug("network: on_wireless_ap_changed: %s", e)
>>               self.client.add_and_activate_connection(None, device, ap_obj_path,
>>                                                       None, None)
> I don't think you need 2 levels of try here, just have separate except
> clauses since the errors are different.

i'll do it,

thanks for the review.


More information about the anaconda-patches mailing list