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
@@ -11,33 +11,37 @@ import sys
|
||||
import re
|
||||
|
||||
import gi
|
||||
gi.require_version('NM', '1.0')
|
||||
|
||||
gi.require_version("NM", "1.0")
|
||||
from gi.repository import GLib, NM
|
||||
|
||||
|
||||
def usage():
|
||||
print('Usage: %s [[id] <id>]' % (sys.argv[0]))
|
||||
print(' %s [[uuid] <uuid>]' % (sys.argv[0]))
|
||||
print("Usage: %s [[id] <id>]" % (sys.argv[0]))
|
||||
print(" %s [[uuid] <uuid>]" % (sys.argv[0]))
|
||||
return 1
|
||||
|
||||
|
||||
def find_connection(nm_client, arg_type, arg_id):
|
||||
for c in nm_client.get_connections():
|
||||
if arg_type in [None, 'id'] and c.get_id() == arg_id:
|
||||
if arg_type in [None, "id"] and c.get_id() == arg_id:
|
||||
return c
|
||||
if arg_type in [None, 'uuid'] and c.get_uuid() == arg_id:
|
||||
if arg_type in [None, "uuid"] and c.get_uuid() == arg_id:
|
||||
return c
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2 or len(sys.argv) > 3:
|
||||
return usage()
|
||||
if len(sys.argv) == 3:
|
||||
arg_type = sys.argv[1]
|
||||
arg_id = sys.argv[2]
|
||||
if arg_type not in ['id', 'uuid']:
|
||||
if arg_type not in ["id", "uuid"]:
|
||||
return usage()
|
||||
else:
|
||||
arg_type = None
|
||||
arg_id = sys.argv[1]
|
||||
arg_log = '%s"%s"' % ((' with %s ' % (arg_type)) if arg_type else '', arg_id)
|
||||
arg_log = '%s"%s"' % ((" with %s " % (arg_type)) if arg_type else "", arg_id)
|
||||
|
||||
main_loop = GLib.MainLoop()
|
||||
|
||||
@@ -45,57 +49,61 @@ def main():
|
||||
|
||||
con = find_connection(nm_client, arg_type, arg_id)
|
||||
if con is None:
|
||||
print('could not find a connection %s' % (arg_log))
|
||||
print("could not find a connection %s" % (arg_log))
|
||||
return 1
|
||||
|
||||
s_con = con.get_setting_connection()
|
||||
if s_con is None:
|
||||
print('connection %s has no [connection] setting' % (arg_log))
|
||||
print("connection %s has no [connection] setting" % (arg_log))
|
||||
return 1
|
||||
|
||||
arg_log = '"%s" (%s)' % (s_con.get_id(), s_con.get_uuid())
|
||||
|
||||
stable_id = s_con.get_stable_id()
|
||||
if not stable_id:
|
||||
print('connection %s has no stable-id set' % (arg_log))
|
||||
print("connection %s has no stable-id set" % (arg_log))
|
||||
return 1
|
||||
|
||||
re_match = re.search('\A(.*)-([0-9]+)\Z', stable_id)
|
||||
re_match = re.search("\A(.*)-([0-9]+)\Z", stable_id)
|
||||
if not re_match:
|
||||
stable_id = stable_id + '-1'
|
||||
stable_id = stable_id + "-1"
|
||||
else:
|
||||
stable_id = re_match.group(1) + '-' + str(int(re_match.group(2)) + 1)
|
||||
stable_id = re_match.group(1) + "-" + str(int(re_match.group(2)) + 1)
|
||||
|
||||
con2 = NM.SimpleConnection.new_clone(con)
|
||||
s_con = con2.get_setting_connection()
|
||||
s_con.set_property(NM.SETTING_CONNECTION_STABLE_ID, stable_id)
|
||||
|
||||
result = {}
|
||||
|
||||
def _update2_cb(con, async_result, user_data):
|
||||
try:
|
||||
r = con.update2_finish(async_result)
|
||||
except Exception as e:
|
||||
result['error'] = e
|
||||
result["error"] = e
|
||||
else:
|
||||
result['result'] = r
|
||||
result["result"] = r
|
||||
main_loop.quit()
|
||||
|
||||
con.update2(con2.to_dbus(NM.ConnectionSerializationFlags.ALL),
|
||||
NM.SettingsUpdate2Flags.BLOCK_AUTOCONNECT,
|
||||
None,
|
||||
None,
|
||||
_update2_cb,
|
||||
None)
|
||||
con.update2(
|
||||
con2.to_dbus(NM.ConnectionSerializationFlags.ALL),
|
||||
NM.SettingsUpdate2Flags.BLOCK_AUTOCONNECT,
|
||||
None,
|
||||
None,
|
||||
_update2_cb,
|
||||
None,
|
||||
)
|
||||
|
||||
main_loop.run()
|
||||
|
||||
if 'error' in result:
|
||||
print('update connection %s failed: %s' % (arg_log, result['error']))
|
||||
if "error" in result:
|
||||
print("update connection %s failed: %s" % (arg_log, result["error"]))
|
||||
return 1
|
||||
|
||||
print('update connection %s succeeded: %s' % (arg_log, result['result']))
|
||||
print("update connection %s succeeded: %s" % (arg_log, result["result"]))
|
||||
print('set stable-id to "%s"' % (stable_id))
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
Reference in New Issue
Block a user