all: reformat python files with python black
Part of !537. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
This commit is contained in:

committed by
Thomas Haller

parent
b6febb0fd0
commit
be822b52e6
@@ -30,42 +30,49 @@ if method == "static":
|
||||
method = "manual"
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
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")
|
||||
|
||||
for c_path in settings.ListConnections():
|
||||
c_proxy = bus.get_object("org.freedesktop.NetworkManager", c_path)
|
||||
c_obj = dbus.Interface(c_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
||||
c_obj = dbus.Interface(
|
||||
c_proxy, "org.freedesktop.NetworkManager.Settings.Connection"
|
||||
)
|
||||
c_settings = c_obj.GetSettings()
|
||||
|
||||
# Look for the requested connection UUID
|
||||
if c_settings['connection']['uuid'] != sys.argv[1]:
|
||||
if c_settings["connection"]["uuid"] != sys.argv[1]:
|
||||
continue
|
||||
|
||||
# add IPv4 setting if it doesn't yet exist
|
||||
if 'ipv4' not in c_settings:
|
||||
c_settings['ipv4'] = {}
|
||||
if "ipv4" not in c_settings:
|
||||
c_settings["ipv4"] = {}
|
||||
|
||||
# clear existing address info
|
||||
if c_settings['ipv4'].has_key('addresses'):
|
||||
del c_settings['ipv4']['addresses']
|
||||
if c_settings['ipv4'].has_key('address-data'):
|
||||
del c_settings['ipv4']['address-data']
|
||||
if c_settings['ipv4'].has_key('gateway'):
|
||||
del c_settings['ipv4']['gateway']
|
||||
if c_settings["ipv4"].has_key("addresses"):
|
||||
del c_settings["ipv4"]["addresses"]
|
||||
if c_settings["ipv4"].has_key("address-data"):
|
||||
del c_settings["ipv4"]["address-data"]
|
||||
if c_settings["ipv4"].has_key("gateway"):
|
||||
del c_settings["ipv4"]["gateway"]
|
||||
|
||||
# set the method and change properties
|
||||
c_settings['ipv4']['method'] = method
|
||||
c_settings["ipv4"]["method"] = method
|
||||
if method == "manual":
|
||||
# Add the static IP address, prefix, and (optional) gateway
|
||||
addr = dbus.Dictionary({'address': sys.argv[3], 'prefix': dbus.UInt32(int(sys.argv[4]))})
|
||||
c_settings['ipv4']['address-data'] = dbus.Array([addr], signature=dbus.Signature('a{sv}'))
|
||||
addr = dbus.Dictionary(
|
||||
{"address": sys.argv[3], "prefix": dbus.UInt32(int(sys.argv[4]))}
|
||||
)
|
||||
c_settings["ipv4"]["address-data"] = dbus.Array(
|
||||
[addr], signature=dbus.Signature("a{sv}")
|
||||
)
|
||||
if len(sys.argv) == 6:
|
||||
c_settings['ipv4']['gateway'] = sys.argv[5]
|
||||
c_settings["ipv4"]["gateway"] = sys.argv[5]
|
||||
|
||||
# Save all the updated settings back to NetworkManager
|
||||
c_obj.Update(c_settings)
|
||||
break
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
|
Reference in New Issue
Block a user