From 2c032d8f1c6292c1338a615e6ec40252889ba85c Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Thu, 22 Jan 2015 00:29:39 +0100 Subject: Imported Upstream version 1.0.0 --- examples/python/gi/Makefile.in | 6 +- examples/python/gi/add_connection.py | 52 ++++++++-------- examples/python/gi/device-state-ip4config.py | 4 +- examples/python/gi/firewall-zone.py | 30 ++++----- examples/python/gi/get-active-connections.py | 4 +- examples/python/gi/get_ips.py | 90 +++++++++++++-------------- examples/python/gi/list-connections.py | 34 ++++------- examples/python/gi/show-wifi-networks.py | 36 ++++++----- examples/python/gi/update-ip4-method.py | 91 ++++++++++++---------------- 9 files changed, 161 insertions(+), 186 deletions(-) (limited to 'examples/python/gi') diff --git a/examples/python/gi/Makefile.in b/examples/python/gi/Makefile.in index 8ea13b18..0f8e3e58 100644 --- a/examples/python/gi/Makefile.in +++ b/examples/python/gi/Makefile.in @@ -129,6 +129,8 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ +BLUEZ5_CFLAGS = @BLUEZ5_CFLAGS@ +BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ @@ -252,6 +254,7 @@ NEWT_CFLAGS = @NEWT_CFLAGS@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ +NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -271,6 +274,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ @@ -297,7 +301,7 @@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ -UDEV_BASE_DIR = @UDEV_BASE_DIR@ +UDEV_DIR = @UDEV_DIR@ USE_NLS = @USE_NLS@ UUID_CFLAGS = @UUID_CFLAGS@ UUID_LIBS = @UUID_LIBS@ diff --git a/examples/python/gi/add_connection.py b/examples/python/gi/add_connection.py index 76c2e94e..bb1163db 100755 --- a/examples/python/gi/add_connection.py +++ b/examples/python/gi/add_connection.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai + # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,21 +17,19 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # # # This example shows how to add a new NM connection profile. -# The code uses libnm-util (NetworkManager) and libnm-glib (NMClient) -# via GObject Introspection. +# The code uses libnm (NM) via GObject Introspection. # # Documentation links: -# https://developer.gnome.org/libnm-glib/0.9/ -# https://developer.gnome.org/libnm-util/0.9/ -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/libnm/1.0/ +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM import sys, uuid main_loop = None @@ -39,19 +39,19 @@ def print_values(setting, key, value, flags, data): # create an Ethernet connection and return it def create_profile(name): - profile = NetworkManager.Connection.new() - s_con = NetworkManager.SettingConnection.new() - s_con.set_property(NetworkManager.SETTING_CONNECTION_ID, name) - s_con.set_property(NetworkManager.SETTING_CONNECTION_UUID, str(uuid.uuid4())) - s_con.set_property(NetworkManager.SETTING_CONNECTION_TYPE, "802-3-ethernet") + profile = NM.SimpleConnection.new() + s_con = NM.SettingConnection.new() + s_con.set_property(NM.SETTING_CONNECTION_ID, name) + s_con.set_property(NM.SETTING_CONNECTION_UUID, str(uuid.uuid4())) + s_con.set_property(NM.SETTING_CONNECTION_TYPE, "802-3-ethernet") - s_wired = NetworkManager.SettingWired.new() + s_wired = NM.SettingWired.new() - s_ip4 = NetworkManager.SettingIP4Config.new() - s_ip4.set_property(NetworkManager.SETTING_IP4_CONFIG_METHOD, "auto") + s_ip4 = NM.SettingIP4Config.new() + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") - s_ip6 = NetworkManager.SettingIP6Config.new() - s_ip6.set_property(NetworkManager.SETTING_IP6_CONFIG_METHOD, "auto") + s_ip6 = NM.SettingIP6Config.new() + s_ip6.set_property(NM.SETTING_IP_CONFIG_METHOD, "auto") profile.add_setting(s_con) profile.add_setting(s_ip4) @@ -64,11 +64,12 @@ def create_profile(name): return profile # callback function -def added_cb(settings, con, error, data): - if error is (None): +def added_cb(client, result, data): + try: + client.add_connection_finish(result) print("The connection profile has been succesfully added to NetworkManager.") - else: - print(error) + except Exception, e: + print("Error: %s" % e) main_loop.quit() if __name__ == "__main__": @@ -85,17 +86,14 @@ if __name__ == "__main__": main_loop = GLib.MainLoop() - # create RemoteSettings object - settings = NMClient.RemoteSettings.new(None); + # create Client object + client = NM.Client.new(None) # create a connection profile for NM con = create_profile(profile_name) # send the connection to NM - if persistent: - settings.add_connection(con, added_cb, None) - else: - settings.add_connection_unsaved(con, added_cb, None) + client.add_connection_async(con, persistent, None, added_cb, None) main_loop.run() diff --git a/examples/python/gi/device-state-ip4config.py b/examples/python/gi/device-state-ip4config.py index be19b996..1a6f7dec 100755 --- a/examples/python/gi/device-state-ip4config.py +++ b/examples/python/gi/device-state-ip4config.py @@ -21,7 +21,7 @@ # import sys -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM # # This example shows how to get NMIP4Config from NMDevice after it is activated. @@ -51,7 +51,7 @@ if __name__ == "__main__": sys.exit('Usage: %s ' % sys.argv[0]) dev_iface = sys.argv[1] - c = NMClient.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) diff --git a/examples/python/gi/firewall-zone.py b/examples/python/gi/firewall-zone.py index 5e5eea91..ed9e5910 100755 --- a/examples/python/gi/firewall-zone.py +++ b/examples/python/gi/firewall-zone.py @@ -16,11 +16,11 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2013 Red Hat, Inc. +# Copyright 2013 - 2014 Red Hat, Inc. # import sys -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import GLib, NM # # This example demonstrates how to get and change firewall zone in a @@ -32,7 +32,7 @@ from gi.repository import GLib, NetworkManager, NMClient # If you used D-Bus calls, you would call GetSettings() and then Update(). # # Links: -# https://developer.gnome.org/libnm-glib/0.9/ +# https://developer.gnome.org/libnm/1.0/ # https://wiki.gnome.org/GObjectIntrospection # https://wiki.gnome.org/PyGObject # @@ -43,7 +43,14 @@ def connection_saved(connection, error, data): print ("Connection '%s' saved.") % (connection.get_id()) main_loop.quit() -def connections_read(settings, data): +if __name__ == "__main__": + if len(sys.argv) != 2 and len(sys.argv) != 3: + sys.exit('Usage: %s [new zone]' % sys.argv[0]) + + main_loop = GLib.MainLoop() + client = NM.Client.new(None) + connections = client.get_connections() + con_name = sys.argv[1] if len(sys.argv) == 3: new_zone = sys.argv[2] @@ -51,7 +58,6 @@ def connections_read(settings, data): new_zone = None found = False - connections = settings.list_connections() for c in connections: if c.get_id() == con_name or c.get_uuid() == con_name: found = True @@ -71,17 +77,3 @@ def connections_read(settings, data): if not found: print ("Error: connection '%s' not found.") % (con_name) main_loop.quit() - - -if __name__ == "__main__": - if len(sys.argv) != 2 and len(sys.argv) != 3: - sys.exit('Usage: %s [new zone]' % sys.argv[0]) - - main_loop = GLib.MainLoop() - settings = NMClient.RemoteSettings.new(None); - - # Connections are read asynchronously, so we have to wait for the - # 'settings' object to tell us that all connections have been read. - settings.connect("connections-read", connections_read, None) - main_loop.run() - diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py index 13f0b031..55ba2d81 100755 --- a/examples/python/gi/get-active-connections.py +++ b/examples/python/gi/get-active-connections.py @@ -21,10 +21,10 @@ # This example lists currently active connections -from gi.repository import GLib, NMClient +from gi.repository import GLib, NM if __name__ == "__main__": - client = NMClient.Client.new() + client = NM.Client.new(None) acons = client.get_active_connections() for ac in acons: print "%s (%s) - %s" % (ac.get_id(), ac.get_uuid(), ac.get_connection_type()) diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py index 6903b6de..690bd6ef 100755 --- a/examples/python/gi/get_ips.py +++ b/examples/python/gi/get_ips.py @@ -17,22 +17,22 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # -import sys, socket, struct -from gi.repository import GLib, NetworkManager, NMClient +import sys, socket +from gi.repository import GLib, NM # # This example shows how to get addresses, routes and DNS information # from NMIP4Config and NMIP6Config (got out of NMDevice) # -def show_addresses(self, family): +def show_addresses(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") @@ -46,24 +46,29 @@ def show_addresses(self, family): for nm_address in nm_addresses: addr = nm_address.get_address() prefix = nm_address.get_prefix() - gateway = nm_address.get_gateway() - if (family == socket.AF_INET): - addr_struct = struct.pack("=I", addr) - gateway_struct = struct.pack("=I", gateway) - else: - addr_struct = addr - gateway_struct = gateway - print("%s/%d %s") % (socket.inet_ntop(family, addr_struct), - prefix, - socket.inet_ntop(family, gateway_struct)) + print("%s/%d") % (addr, prefix) +def show_gateway(dev, family): + if (family == socket.AF_INET): + ip_cfg = dev.get_ip4_config() + else: + ip_cfg = dev.get_ip6_config() + + if ip_cfg is None: + gw = "None" + else: + gw = ip_cfg.get_gateway() + if gw == '': + gw = "None" + + print(gw) -def show_routes(self, family): +def show_routes(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") @@ -80,43 +85,24 @@ def show_routes(self, family): next_hop = nm_route.get_next_hop() metric = nm_route.get_metric() - if (family == socket.AF_INET): - dest_struct = struct.pack("=I", dest) - next_hop_struct = struct.pack("=I", next_hop) - else: - dest_struct = dest - next_hop_struct = next_hop - print("%s/%d %s %d") % (socket.inet_ntop(family, dest_struct), - prefix, - socket.inet_ntop(family, next_hop_struct), - metric) + print("%s/%d %s %d") % (dest, prefix, next_hop, metric) -def show_dns(self, family): +def show_dns(dev, family): if (family == socket.AF_INET): - ip_cfg = self.get_ip4_config() + ip_cfg = dev.get_ip4_config() else: - ip_cfg = self.get_ip6_config() + ip_cfg = dev.get_ip6_config() if ip_cfg is None: print("None") return + print ("Nameservers: %s") % (ip_cfg.get_nameservers()) + print ("Domains: %s") % (ip_cfg.get_domains()) + print ("Searches: %s") % (ip_cfg.get_searches()) if (family == socket.AF_INET): - print ("Domains: %s") % (ip_cfg.get_domains()) - print ("Searches: %s") % (ip_cfg.get_searches()) - print("Nameservers:") - nameservers = ip_cfg.get_nameservers() - for dns in nameservers: - print socket.inet_ntop(family, struct.pack("=I", dns)) - else: - print ("Domains: %s") % (ip_cfg.get_domains()) - print ("Searches: %s") % (ip_cfg.get_searches()) - print("Nameservers:") - num = ip_cfg.get_num_nameservers() - for i in range(0,num): - dns = ip_cfg.get_nameserver(i) - print socket.inet_ntop(family, dns) + print ("WINS: %s") % (ip_cfg.get_wins_servers()) if __name__ == "__main__": @@ -124,7 +110,7 @@ if __name__ == "__main__": sys.exit('Usage: %s ' % sys.argv[0]) dev_iface = sys.argv[1] - c = NMClient.Client.new() + c = NM.Client.new(None) dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) @@ -136,6 +122,11 @@ if __name__ == "__main__": show_addresses(dev, socket.AF_INET) print + print("IPv4 gateway:") + print("-------------") + show_gateway(dev, socket.AF_INET) + print + print("IPv4 routes:") print("------------") show_routes(dev, socket.AF_INET) @@ -146,6 +137,11 @@ if __name__ == "__main__": show_addresses(dev, socket.AF_INET6) print + print("IPv6 gateway:") + print("-------------") + show_gateway(dev, socket.AF_INET6) + print + print "IPv6 routes:" print("------------") show_routes(dev, socket.AF_INET6) diff --git a/examples/python/gi/list-connections.py b/examples/python/gi/list-connections.py index b6452d35..34b559fc 100755 --- a/examples/python/gi/list-connections.py +++ b/examples/python/gi/list-connections.py @@ -1,5 +1,7 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai + # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,36 +17,26 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2012 Red Hat, Inc. +# Copyright 2012 - 2014 Red Hat, Inc. # -from gi.repository import GLib, NetworkManager, NMClient +from gi.repository import NM # This example asks settings service for all configured connections. -# Unfortunately, at this time since libnm-glib still makes heavy use of -# GValue and GHashTable (rather than GVariant), libnm-glib isn't fully -# usable from GObject Introspection-ready languages. Most functions will -# work fine, but e. g. nm_connection_to_hash() causes assertion failures. - -main_loop = None def print_values(setting, key, value, flags, data): print " %s.%s: %s" % (setting.get_name(), key, value) -def connections_read(settings): - connections = settings.list_connections() +if __name__ == "__main__": + # create Client object + client = NM.Client.new(None) + + # get all connections + connections = client.get_connections() + + # print the connections' details for c in connections: - print "--- %s : %s" % (c.get_id(), c.get_path()) + print "=== %s : %s ===" % (c.get_id(), c.get_path()) c.for_each_setting_value(print_values, None) print "\n" - main_loop.quit() - -if __name__ == "__main__": - main_loop = GLib.MainLoop() - settings = NMClient.RemoteSettings.new(None); - - # connections are read asynchronously, so we need to wait for the - # settings object to tell us that it's read all connections - settings.connect("connections-read", connections_read) - main_loop.run() diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py index 9d9e3471..7f3bd2db 100755 --- a/examples/python/gi/show-wifi-networks.py +++ b/examples/python/gi/show-wifi-networks.py @@ -20,33 +20,32 @@ # Copyright (C) 2013 Red Hat, Inc. # -from gi.repository import NetworkManager, NMClient +import locale +from gi.repository import NM # # This example lists Wi-Fi access points NetworkManager scanned on Wi-Fi devices. -# It calls libnm-glib functions using GObject introspection. +# It calls libnm functions using GObject introspection. # # Note the second line of the file: coding=utf-8 # It is necessary because we use unicode characters and python would produce # an error without it: http://www.python.org/dev/peps/pep-0263/ # -signal_bars = { - 0 : "____", - 1 : "▂___", - 2 : "▂▄__", - 3 : "▂▄▆_", - 4 : "▂▄▆█" -} - def clamp(value, minvalue, maxvalue): return max(minvalue, min(value, maxvalue)) +def ssid_to_utf8(ap): + ssid = ap.get_ssid() + if not ssid: + return "" + return NM.utils_ssid_to_utf8(ap.get_ssid().get_data()) + def print_device_info(device): active_ap = dev.get_active_access_point() ssid = None if active_ap is not None: - ssid = active_ap.get_ssid() + ssid = ssid_to_utf8(active_ap) info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid) print info print '=' * len(info) @@ -54,19 +53,24 @@ def print_device_info(device): def print_ap_info(ap): strength = ap.get_strength() frequency = ap.get_frequency() - print "SSID: %s" % (ap.get_ssid()) + print "SSID: %s" % (ssid_to_utf8(ap)) print "BSSID: %s" % (ap.get_bssid()) print "Frequency: %s" % (frequency) - print "Channel: %s" % (NetworkManager.utils_wifi_freq_to_channel(frequency)) - print "Strength: %s %s%%" % (signal_bars[(clamp(strength-5, 0, 99)+24)/25], strength) + print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency)) + print "Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength) print if __name__ == "__main__": - nmc = NMClient.Client.new() + # Python apparently doesn't call setlocale() on its own? We have to call this or else + # NM.utils_wifi_strength_bars() will think the locale is ASCII-only, and return the + # fallback characters rather than the unicode bars + locale.setlocale(locale.LC_ALL, '') + + nmc = NM.Client.new(None) devs = nmc.get_devices() for dev in devs: - if dev.get_device_type() == NetworkManager.DeviceType.WIFI: + if dev.get_device_type() == NM.DeviceType.WIFI: print_device_info(dev) for ap in dev.get_access_points(): print_ap_info(ap) diff --git a/examples/python/gi/update-ip4-method.py b/examples/python/gi/update-ip4-method.py index 2fe12693..983578cf 100755 --- a/examples/python/gi/update-ip4-method.py +++ b/examples/python/gi/update-ip4-method.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- Mode: Python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# vim: ft=python ts=4 sts=4 sw=4 et ai # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,35 +16,43 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Copyright (C) 2014 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # # # This example updates a connection's IPv4 method with the Update() method -# using the libnm-glib GObject-based convenience APIs. +# using the libnm GObject-based convenience APIs. # # Configuration settings are described at -# https://developer.gnome.org/NetworkManager/0.9/ref-settings.html +# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html # -from gi.repository import GLib, NetworkManager, NMClient -import sys, struct, socket +from gi.repository import GLib, NM +import sys, socket -def ip_to_int(ip_string): - return struct.unpack("=I", socket.inet_aton(ip_string))[0] +if __name__ == "__main__": + # parse and validate arguments + if len(sys.argv) < 3: + print "Usage: %s [address prefix gateway]" % sys.argv[0] + sys.exit(1) + + method = sys.argv[2] + if (method == "static" or method == "manual") and len(sys.argv) < 5: + print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) + sys.exit(1) -# callback function -def commit_cb(connection, error, data): - if error is (None): - print("The connection profile has been updated.") - else: - print(error) - main_loop.quit() + uuid = sys.argv[1] -def connections_read_cb(settings, data): - uuid, method, args = data + # Convert method to NM method + if method == "static": + method = "manual" + + main_loop = GLib.MainLoop() - all_connections = settings.list_connections() + # create Client object + client = NM.Client.new(None) + + all_connections = client.get_connections() for c in all_connections: if c.get_uuid() != uuid: continue @@ -51,46 +60,26 @@ def connections_read_cb(settings, data): # add IPv4 setting if it doesn't yet exist s_ip4 = c.get_setting_ip4_config() if not s_ip4: - s_ip4 = NetworkManager.SettingIP4Config.new() + s_ip4 = NM.SettingIP4Config.new() c.add_setting(s_ip4) # set the method and change properties - s_ip4.set_property(NetworkManager.SETTING_IP4_CONFIG_METHOD, method) + s_ip4.set_property(NM.SETTING_IP_CONFIG_METHOD, method) if method == "auto": - # remove addresses + # 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 = NetworkManager.IP4Address.new() - addr.set_address(ip_to_int(sys.argv[3])) - addr.set_prefix(int(sys.argv[4])) - if len(sys.argv) == 6: - addr.set_gateway(ip_to_int(sys.argv[5])) + addr = NM.IPAddress.new(socket.AF_INET, sys.argv[3], int(sys.argv[4])) s_ip4.add_address(addr) - - c.commit_changes(commit_cb, None) - -if __name__ == "__main__": - # parse and validate arguments - if len(sys.argv) < 3: - print "Usage: %s [address prefix gateway]" % sys.argv[0] - sys.exit(1) - - method = sys.argv[2] - if method == "static" and len(sys.argv) < 5: - print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) - sys.exit(1) - - # Convert method to NM method - if method == "static": - method = "manual" - - main_loop = GLib.MainLoop() - - # create RemoteSettings object and attach to the "connections-read" signal - # to wait for connections to be loaded asynchronously - settings = NMClient.RemoteSettings.new(None) - settings.connect('connections-read', connections_read_cb, (sys.argv[1], method, sys.argv)) - - main_loop.run() + 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, e: + print("Error: %s" % e) + break -- cgit 1.3.0-6-gf8a5