diff options
| author | Michael Biebl <biebl@debian.org> | 2024-09-01 22:38:35 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2024-09-01 22:38:35 +0200 |
| commit | f9bfd1158b8d08d6a5ed3bb7cc1ba7a6455e5201 (patch) | |
| tree | 10267dcf5b842b7c638a79bd6851549cd849b81d /examples | |
| parent | 681dfc70ef98f6ed0c05bcb0fbff00e3fc0799ea (diff) | |
New upstream version 1.49.90 upstream/1.49.90
Diffstat (limited to 'examples')
| -rwxr-xr-x | examples/python/gi/gmaincontext.py | 2 | ||||
| -rwxr-xr-x | examples/python/gi/update-ip4-method.py | 53 |
2 files changed, 27 insertions, 28 deletions
diff --git a/examples/python/gi/gmaincontext.py b/examples/python/gi/gmaincontext.py index 25283f18..fcbcd61b 100755 --- a/examples/python/gi/gmaincontext.py +++ b/examples/python/gi/gmaincontext.py @@ -14,7 +14,7 @@ # API (like NM.Client.new()) is for simple programs but usually not best # for using NMClient for real applications. # -# To learn more about GMainContext, read https://developer.gnome.org/SearchProvider/documentation/tutorials/main-contexts.html +# To learn more about GMainContext, read https://developer.gnome.org/documentation/tutorials/main-contexts.html # When I say "mainloop" or "event loop", I mean GMainContext. GMainLoop is # a small wrapper around GMainContext to run the context with a boolean # flag. diff --git a/examples/python/gi/update-ip4-method.py b/examples/python/gi/update-ip4-method.py index 036606c4..3017480e 100755 --- a/examples/python/gi/update-ip4-method.py +++ b/examples/python/gi/update-ip4-method.py @@ -42,33 +42,32 @@ if __name__ == "__main__": # create Client object client = NM.Client.new(None) - all_connections = client.get_connections() - for c in all_connections: - if c.get_uuid() != uuid: - continue + try: + conn = next(c for c in client.get_connections() if c.get_uuid() == uuid) + except StopIteration: + sys.exit("not found connection with uuid=%s" % uuid) - # add IPv4 setting if it doesn't yet exist - s_ip4 = c.get_setting_ip4_config() - if not s_ip4: - s_ip4 = NM.SettingIP4Config.new() - c.add_setting(s_ip4) + # add IPv4 setting if it doesn't yet exist + s_ip4 = conn.get_setting_ip4_config() + if not s_ip4: + s_ip4 = NM.SettingIP4Config.new() + conn.add_setting(s_ip4) - # set the method and change properties - s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, method) - if method == "auto": - # remove addresses and gateway - s_ip4.clear_addresses() - s_ip4.props.gateway = None - elif method == "manual": - # Add the static IP address, prefix, and (optional) gateway - addr = NM.IPAddress.new(socket.AF_INET, sys.argv[3], int(sys.argv[4])) - s_ip4.add_address(addr) - if len(sys.argv) == 6: - s_ip4.props.gateway = sys.argv[5] + # set the method and change properties + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, method) + if method == "auto": + # remove addresses and gateway + s_ip4.clear_addresses() + s_ip4.props.gateway = None + elif method == "manual": + # Add the static IP address, prefix, and (optional) gateway + addr = NM.IPAddress.new(socket.AF_INET, sys.argv[3], int(sys.argv[4])) + s_ip4.add_address(addr) + if len(sys.argv) == 6: + s_ip4.props.gateway = sys.argv[5] - try: - c.commit_changes(True, None) - print("The connection profile has been updated.") - except Exception as e: - sys.stderr.write("Error: %s\n" % e) - break + try: + conn.commit_changes(True, None) + print("The connection profile has been updated.") + except Exception as e: + sys.stderr.write("Error: %s\n" % e) |