[Sugar-devel] [PATCH sugar v2] Don't break if we may not own NetworkManagerUserSettings

Sascha Silbe silbe at activitycentral.com
Thu Mar 10 06:52:35 EST 2011


The user might not have privileges to handle user settings - e.g. because
they are logging in remotely (LTSP-style setups), or because NetworkManager
was only installed for testing purposes or dependency reasons.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
v1->v2: use DummyNMSettings class instead of assigning a string to
        _nm_settings

 src/jarabe/desktop/meshbox.py |    2 +-
 src/jarabe/model/network.py   |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index ad4b873..e1a3e51 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -311,7 +311,7 @@ class NetworkManagerObserver(object):
                                       dbus_interface=_NM_IFACE)

         settings = network.get_settings()
-        if settings is not None:
+        if not isinstance(settings, network.DummyNMSettings):
             settings.secrets_request.connect(self.__secrets_request_cb)

     def __secrets_request_cb(self, **kwargs):
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index f265ae4..e55322b 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -535,6 +535,17 @@ class NMSettings(dbus.service.Object):
                 self.connections.pop(uuid)


+class DummyNMSettings(object):
+    """
+    Dummy object used when we don't own the NetworkManager user settings.
+    """
+
+    connections = {}
+
+    def clear_wifi_connections(self):
+        logging.debug('DummyNMSettings.clear_wifi_connections called')
+
+
 class SecretsResponse(object):
     """Intermediate object to report the secrets from the dialog
     back to the connection object and which will inform NM
@@ -815,6 +826,8 @@ def get_settings():
             _nm_settings = NMSettings()
         except dbus.DBusException:
             logging.exception('Cannot create the UserSettings service.')
+            _nm_settings = DummyNMSettings()
+
         load_connections()
     return _nm_settings

--
1.7.2.3



More information about the Sugar-devel mailing list