all: reformat python files with python black

Part of !537.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
This commit is contained in:
Sayed Shah
2020-06-09 16:28:32 -04:00
committed by Thomas Haller
parent b6febb0fd0
commit be822b52e6
44 changed files with 3179 additions and 1961 deletions

View File

@@ -8,11 +8,11 @@
# Run this script without any arguments to list the available connection uuids.
# The uuid of the connection to activate
CONNECTION_UUID="ac6dc9b2-85ef-4311-83d8-add5d7db3f59"
CONNECTION_UUID = "ac6dc9b2-85ef-4311-83d8-add5d7db3f59"
# UID to use. Note that NM only allows the owner of the connection to activate it.
#UID=1000
UID=0
# UID=1000
UID = 0
import sys
import os
@@ -22,20 +22,27 @@ import gobject
DBusGMainLoop(set_as_default=True)
def get_connections():
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager/Settings')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings')
proxy = bus.get_object(
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings"
)
iface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.NetworkManager.Settings"
)
return iface.ListConnections()
def get_connection_by_uuid(uuid):
bus = dbus.SystemBus()
for c in get_connections():
proxy = bus.get_object('org.freedesktop.NetworkManager', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
proxy = bus.get_object("org.freedesktop.NetworkManager", c)
iface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.NetworkManager.Settings.Connection"
)
settings = iface.GetSettings()
if settings['connection']['uuid'] == uuid:
if settings["connection"]["uuid"] == uuid:
return c
return None
@@ -44,29 +51,39 @@ def get_connection_by_uuid(uuid):
def list_uuids():
bus = dbus.SystemBus()
for c in get_connections():
proxy = bus.get_object('org.freedesktop.NetworkManager', c)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
proxy = bus.get_object("org.freedesktop.NetworkManager", c)
iface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.NetworkManager.Settings.Connection"
)
settings = iface.GetSettings()
conn = settings['connection']
print("%s - %s (%s)" % (conn['uuid'], conn['id'], conn['type']))
conn = settings["connection"]
print("%s - %s (%s)" % (conn["uuid"], conn["id"], conn["type"]))
def get_active_connection_path(uuid):
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
active_connections = iface.Get('org.freedesktop.NetworkManager', 'ActiveConnections')
proxy = bus.get_object(
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
)
iface = dbus.Interface(proxy, dbus_interface="org.freedesktop.DBus.Properties")
active_connections = iface.Get(
"org.freedesktop.NetworkManager", "ActiveConnections"
)
for a in active_connections:
proxy = bus.get_object('org.freedesktop.NetworkManager', a)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
path = iface.Get('org.freedesktop.NetworkManager.Connection.Active', 'Connection')
proxy = bus.get_object("org.freedesktop.NetworkManager", a)
iface = dbus.Interface(proxy, dbus_interface="org.freedesktop.DBus.Properties")
path = iface.Get(
"org.freedesktop.NetworkManager.Connection.Active", "Connection"
)
proxy = bus.get_object('org.freedesktop.NetworkManager', path)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
proxy = bus.get_object("org.freedesktop.NetworkManager", path)
iface = dbus.Interface(
proxy, dbus_interface="org.freedesktop.NetworkManager.Settings.Connection"
)
settings = iface.GetSettings()
if settings['connection']['uuid'] == uuid:
if settings["connection"]["uuid"] == uuid:
return a
return None
@@ -74,19 +91,21 @@ def get_active_connection_path(uuid):
def get_wifi_device_path():
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager')
proxy = bus.get_object(
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
)
iface = dbus.Interface(proxy, dbus_interface="org.freedesktop.NetworkManager")
devices = iface.GetDevices()
for d in devices:
proxy = bus.get_object('org.freedesktop.NetworkManager', d)
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
devtype = iface.Get('org.freedesktop.NetworkManager.Device', 'DeviceType')
proxy = bus.get_object("org.freedesktop.NetworkManager", d)
iface = dbus.Interface(proxy, dbus_interface="org.freedesktop.DBus.Properties")
devtype = iface.Get("org.freedesktop.NetworkManager.Device", "DeviceType")
if devtype == 2:
return d
return None
def activate_connection(connection_path, device_path):
def activate_connection(connection_path, device_path):
def reply_handler(opath):
print("Success: device activating")
sys.exit(0)
@@ -96,14 +115,18 @@ def activate_connection(connection_path, device_path):
sys.exit(1)
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager')
iface.ActivateConnection('org.freedesktop.NetworkManager',
connection_path,
device_path,
"/",
reply_handler=reply_handler,
error_handler=error_handler)
proxy = bus.get_object(
"org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager"
)
iface = dbus.Interface(proxy, dbus_interface="org.freedesktop.NetworkManager")
iface.ActivateConnection(
"org.freedesktop.NetworkManager",
connection_path,
device_path,
"/",
reply_handler=reply_handler,
error_handler=error_handler,
)
# Change the UID first if required
@@ -135,4 +158,3 @@ print("Activating connection...")
activate_connection(connection_path, device_path)
loop = gobject.MainLoop()
loop.run()