about summary refs log tree commit diff
path: root/examples/python/dbus/update-secrets.py
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
committerMichael Biebl <biebl@debian.org>2020-06-28 18:58:14 +0200
commita54ac63bbf9b2c71026ac9028a8ffaf186cf3c82 (patch)
tree6a32883bd916c4096357b35298beff6db8bcd0b5 /examples/python/dbus/update-secrets.py
parent45e8e1149027529194982212c804c0468aa01d98 (diff)
New upstream version 1.25.90 upstream/1.25.90
Diffstat (limited to 'examples/python/dbus/update-secrets.py')
-rwxr-xr-xexamples/python/dbus/update-secrets.py48
1 files changed, 31 insertions, 17 deletions
diff --git a/examples/python/dbus/update-secrets.py b/examples/python/dbus/update-secrets.py
index a0b53b7c..d5c20b2d 100755
--- a/examples/python/dbus/update-secrets.py
+++ b/examples/python/dbus/update-secrets.py
@@ -18,6 +18,7 @@ import sys
 
 bus = dbus.SystemBus()
 
+
 def change_secrets_in_one_setting(proxy, config, setting_name):
     # Add new secret values to the connection config
     try:
@@ -29,50 +30,62 @@ def change_secrets_in_one_setting(proxy, config, setting_name):
         # Ask user for new secrets and put them into our connection config
         for setting in secrets:
             for key in secrets[setting]:
-                new_secret = raw_input ("Enter new secret for '%s' in '%s': " % (key, setting))
+                new_secret = raw_input(
+                    "Enter new secret for '%s' in '%s': " % (key, setting)
+                )
                 config[setting_name][key] = new_secret
     except Exception as e:
-        #code = str(e).split(':')[0]
-        #print("Exception:" + str(e))
+        # code = str(e).split(':')[0]
+        # print("Exception:" + str(e))
         pass
 
+
 def change_secrets(con_path, config):
     # Get existing secrets; we grab the secrets for each type of connection
     # (since there isn't a "get all secrets" call because most of the time
     # you only need 'wifi' secrets or '802.1x' secrets, not everything) and
     # set new values into the connection settings (config)
     con_proxy = bus.get_object("org.freedesktop.NetworkManager", con_path)
-    connection_secrets = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
-    change_secrets_in_one_setting(connection_secrets, config, '802-11-wireless')
-    change_secrets_in_one_setting(connection_secrets, config, '802-11-wireless-security')
-    change_secrets_in_one_setting(connection_secrets, config, '802-1x')
-    change_secrets_in_one_setting(connection_secrets, config, 'gsm')
-    change_secrets_in_one_setting(connection_secrets, config, 'cdma')
-    change_secrets_in_one_setting(connection_secrets, config, 'ppp')
+    connection_secrets = dbus.Interface(
+        con_proxy, "org.freedesktop.NetworkManager.Settings.Connection"
+    )
+    change_secrets_in_one_setting(connection_secrets, config, "802-11-wireless")
+    change_secrets_in_one_setting(
+        connection_secrets, config, "802-11-wireless-security"
+    )
+    change_secrets_in_one_setting(connection_secrets, config, "802-1x")
+    change_secrets_in_one_setting(connection_secrets, config, "gsm")
+    change_secrets_in_one_setting(connection_secrets, config, "cdma")
+    change_secrets_in_one_setting(connection_secrets, config, "ppp")
+
 
 def find_connection(name):
     # Ask the settings service for the list of connections it provides
     global con_path
-    proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
+    proxy = bus.get_object(
+        "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings"
+    )
     settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
     connection_paths = settings.ListConnections()
 
     # Get the settings and look for connection's name
     for path in connection_paths:
         con_proxy = bus.get_object("org.freedesktop.NetworkManager", path)
-        connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
+        connection = dbus.Interface(
+            con_proxy, "org.freedesktop.NetworkManager.Settings.Connection"
+        )
         try:
             config = connection.GetSettings()
         except Exception as e:
             pass
 
         # Find connection by the id
-        s_con = config['connection']
-        if name == s_con['id']:
+        s_con = config["connection"]
+        if name == s_con["id"]:
             con_path = path
             return config
         # Find connection by the uuid
-        if name == s_con['uuid']:
+        if name == s_con["uuid"]:
             con_path = path
             return config
 
@@ -96,8 +109,9 @@ if con:
 
     # Change the connection with Update()
     proxy = bus.get_object("org.freedesktop.NetworkManager", con_path)
-    settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings.Connection")
+    settings = dbus.Interface(
+        proxy, "org.freedesktop.NetworkManager.Settings.Connection"
+    )
     settings.Update(con)
 else:
     sys.exit("No connection '%s' found" % sys.argv[1])
-