diff options
Diffstat (limited to 'examples')
37 files changed, 149 insertions, 431 deletions
diff --git a/examples/C/glib/add-connection-gdbus.c b/examples/C/glib/add-connection-gdbus.c index 1045db38..7c8edf68 100644 --- a/examples/C/glib/add-connection-gdbus.c +++ b/examples/C/glib/add-connection-gdbus.c @@ -124,6 +124,11 @@ main (int argc, char *argv[]) GDBusProxy *proxy; GError *error = NULL; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, diff --git a/examples/C/glib/add-connection-libnm.c b/examples/C/glib/add-connection-libnm.c index 18b3d680..86915ea2 100644 --- a/examples/C/glib/add-connection-libnm.c +++ b/examples/C/glib/add-connection-libnm.c @@ -105,6 +105,11 @@ main (int argc, char *argv[]) GMainLoop *loop; GError *error = NULL; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + loop = g_main_loop_new (NULL, FALSE); /* Connect to NetworkManager */ diff --git a/examples/C/glib/get-active-connections-gdbus.c b/examples/C/glib/get-active-connections-gdbus.c index 033582fb..217fd7ac 100644 --- a/examples/C/glib/get-active-connections-gdbus.c +++ b/examples/C/glib/get-active-connections-gdbus.c @@ -251,6 +251,11 @@ main (int argc, char *argv[]) { GDBusProxy *props_proxy; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + /* Create a D-Bus proxy to get the object properties from the NM Manager * object. NM_DBUS_* defines are from nm-dbus-interface.h. */ diff --git a/examples/C/glib/get-ap-info-libnm.c b/examples/C/glib/get-ap-info-libnm.c index b312356c..a548d12d 100644 --- a/examples/C/glib/get-ap-info-libnm.c +++ b/examples/C/glib/get-ap-info-libnm.c @@ -79,7 +79,7 @@ show_access_point_info (NMAccessPoint *ap) { guint32 flags, wpa_flags, rsn_flags, freq, bitrate; guint8 strength; - GBytes *ssid; + GBytes *ssid; const char *hwaddr; NM80211Mode mode; char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str; @@ -158,7 +158,7 @@ show_wifi_device_info (NMDevice *device) const char *iface; const char *driver; guint32 speed; - GBytes *active_ssid; + GBytes *active_ssid; char *active_ssid_str = NULL; int i; @@ -202,6 +202,11 @@ main (int argc, char *argv[]) int i; GError *error = NULL; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + /* Get NMClient object */ client = nm_client_new (NULL, &error); if (!client) { diff --git a/examples/C/glib/list-connections-gdbus.c b/examples/C/glib/list-connections-gdbus.c index b8e77dc9..088df1d8 100644 --- a/examples/C/glib/list-connections-gdbus.c +++ b/examples/C/glib/list-connections-gdbus.c @@ -65,6 +65,11 @@ main (int argc, char *argv[]) { GDBusProxy *proxy; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + /* Create a D-Bus proxy; NM_DBUS_* defined in nm-dbus-interface.h */ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, diff --git a/examples/C/glib/list-connections-libnm.c b/examples/C/glib/list-connections-libnm.c index 1b3ed8d1..5dc38201 100644 --- a/examples/C/glib/list-connections-libnm.c +++ b/examples/C/glib/list-connections-libnm.c @@ -69,6 +69,11 @@ main (int argc, char *argv[]) const GPtrArray *connections; int i; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + if (!(client = nm_client_new (NULL, &error))) { g_message ("Error: Could not connect to NetworkManager: %s.", error->message); g_error_free (error); diff --git a/examples/C/glib/meson.build b/examples/C/glib/meson.build deleted file mode 100644 index edc4dbb1..00000000 --- a/examples/C/glib/meson.build +++ /dev/null @@ -1,19 +0,0 @@ -examples = [ - ['add-connection-gdbus', [libnm_enum[1]], [libnm_inc], [uuid_dep]], - ['add-connection-libnm', [], [], [libnm_dep]], - ['get-active-connections-gdbus', [libnm_enum[1]], [libnm_inc], []], - ['get-ap-info-libnm', [], [], [libnm_dep]], - ['list-connections-gdbus', [], [], []], - ['list-connections-libnm', [], [], [libnm_dep]], - ['monitor-nm-running-gdbus', [], [], []], - ['monitor-nm-state-gdbus', [], [], []] -] - -foreach example: examples - executable( - example[0], - [example[0] + '.c'] + example[1], - include_directories: example[2], - dependencies: [nm_core_dep] + example[3], - ) -endforeach diff --git a/examples/C/glib/monitor-nm-running-gdbus.c b/examples/C/glib/monitor-nm-running-gdbus.c index 68617884..c19569b5 100644 --- a/examples/C/glib/monitor-nm-running-gdbus.c +++ b/examples/C/glib/monitor-nm-running-gdbus.c @@ -56,6 +56,11 @@ main (int argc, char *argv[]) GMainLoop *loop; GBusNameWatcherFlags flags; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + g_print ("Monitor 'org.freedesktop.NetworkManager' D-Bus name\n"); g_print ("===================================================\n"); diff --git a/examples/C/glib/monitor-nm-state-gdbus.c b/examples/C/glib/monitor-nm-state-gdbus.c index 204ff570..913644d2 100644 --- a/examples/C/glib/monitor-nm-state-gdbus.c +++ b/examples/C/glib/monitor-nm-state-gdbus.c @@ -90,6 +90,11 @@ main (int argc, char *argv[]) GDBusProxyFlags flags; GDBusProxy *proxy; +#if !GLIB_CHECK_VERSION (2, 35, 0) + /* Initialize GType system */ + g_type_init (); +#endif + /* Monitor 'StateChanged' signal on 'org.freedesktop.NetworkManager' interface */ g_print ("Monitor NetworkManager's state\n"); g_print ("==============================\n"); diff --git a/examples/C/qt/meson.build b/examples/C/qt/meson.build deleted file mode 100644 index d92205b1..00000000 --- a/examples/C/qt/meson.build +++ /dev/null @@ -1,47 +0,0 @@ -examples = [ - ['add-connection-wired', []], - ['list-connections', []], - ['change-ipv4-addresses', []] -] - -incs = [ - top_inc, - libnm_core_inc -] - -qt_core_dep = dependency('QtCore', version: '>= 4') - -deps = [ - dbus_dep, - dbus_glib_dep, - qt_core_dep, - dependency('QtDBus'), - dependency('QtNetwork') -] - -moc = find_program('moc-qt4', required: false) -if not moc.found() - moc = qt_core_dep.get_pkgconfig_variable('moc_location') -endif - -example = 'monitor-nm-running' -output = example + '.moc' - -example_moc = custom_target( - output, - input: example + '.cpp', - output: output, - command: [moc, '-i', '@INPUT@', '-o', '@OUTPUT@'] -) - -examples += [[example, [example_moc]]] - -foreach example: examples - executable( - example[0], - example[0] + '.cpp', - include_directories: incs, - dependencies: deps, - link_depends: example[1] - ) -endforeach diff --git a/examples/js/get_ips.js b/examples/js/get_ips.js deleted file mode 100755 index 490ecb2a..00000000 --- a/examples/js/get_ips.js +++ /dev/null @@ -1,184 +0,0 @@ -#!/usr/bin/env gjs - -/* - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2014,2017 Red Hat, Inc. - */ - -const System = imports.system; -const NM = imports.gi.NM; -const GLib = imports.gi.GLib; - -/* - * This example shows how to get addresses, routes and DNS information - * from NMIP4Config and NMIP6Config (got out of NMDevice) - */ - -function show_addresses (dev, family) -{ - let ip_cfg; - if (family == GLib.SYSDEF_AF_INET) - ip_cfg = dev.get_ip4_config (); - else - ip_cfg = dev.get_ip6_config (); - - if (ip_cfg == null) { - print ("None"); - return; - } - - let nm_addresses = ip_cfg.get_addresses (); - if (nm_addresses.length == 0) { - print ("None"); - return; - } - - for (let nm_address of nm_addresses) { - let addr = nm_address.get_address (); - let prefix = nm_address.get_prefix (); - - print (addr + "/" + prefix); - } -} - -function show_gateway (dev, family) -{ - let ip_cfg; - if ((family == GLib.SYSDEF_AF_INET)) - ip_cfg = dev.get_ip4_config (); - else - ip_cfg = dev.get_ip6_config (); - - let gw; - if (ip_cfg == null) - gw = "None" - else { - gw = ip_cfg.get_gateway (); - if (gw == '') - gw = "None" - } - - print (gw); -} - -function show_routes (dev, family) -{ - let ip_cfg; - if ((family == GLib.SYSDEF_AF_INET)) - ip_cfg = dev.get_ip4_config (); - else - ip_cfg = dev.get_ip6_config (); - - if (ip_cfg == null) { - print ("None"); - return; - } - - let nm_routes = ip_cfg.get_routes (); - if (nm_routes.length == 0) { - print ("None"); - return; - } - - for (let nm_route of nm_routes) { - let dest = nm_route.get_dest (); - let prefix = nm_route.get_prefix (); - let next_hop = nm_route.get_next_hop (); - let metric = nm_route.get_metric (); - - print (dest + "/" + prefix + " " + next_hop + " " + metric); - } -} - -function show_dns (dev, family) -{ - let ip_cfg; - if ((family == GLib.SYSDEF_AF_INET)) - ip_cfg = dev.get_ip4_config (); - else - ip_cfg = dev.get_ip6_config (); - - if (ip_cfg == null) { - print ("None"); - return; - } - - print ("Nameservers: " + ip_cfg.get_nameservers ()); - print ("Domains: " + ip_cfg.get_domains ()); - print ("Searches: " + ip_cfg.get_searches ()); - if ((family == GLib.SYSDEF_AF_INET)) - print ("WINS: " + ip_cfg.get_wins_servers ()); -} - -if (ARGV.length != 1) { - print ("Usage: get_ips.js <interface>"); - System.exit (1); -} - - -let dev_iface = ARGV[0]; -let c = NM.Client.new (null); - -let dev = c.get_device_by_iface (dev_iface); - -if (dev == null) { - print ("Device '%s' not found " + dev_iface); - System.exit (1); -} - -print ("Device: " + dev_iface + " - " + dev.get_type_description ()); -print ("---------------------------------------"); -print (); - -print ("IPv4 addresses:"); -print ("---------------"); -show_addresses (dev, GLib.SYSDEF_AF_INET); -print (); - -print ("IPv4 gateway:"); -print ("-------------"); -show_gateway (dev, GLib.SYSDEF_AF_INET); -print (); - -print ("IPv4 routes:"); -print ("------------"); -show_routes (dev, GLib.SYSDEF_AF_INET); -print (); - -print ("IPv6 addresses:"); -print ("---------------"); -show_addresses (dev, GLib.SYSDEF_AF_INET6); -print (); - -print ("IPv6 gateway:"); -print ("-------------"); -show_gateway (dev, GLib.SYSDEF_AF_INET6); -print (); - -print ("IPv6 routes:"); -print ("------------"); -show_routes (dev, GLib.SYSDEF_AF_INET6); -print (); - -print ("IPv4 DNS:"); -print ("------------"); -show_dns (dev, GLib.SYSDEF_AF_INET); -print (); - -print ("IPv6 DNS:"); -print ("------------"); -show_dns (dev, GLib.SYSDEF_AF_INET6); -print (); diff --git a/examples/python/dbus/add-connection-compat.py b/examples/python/dbus/add-connection-compat.py index 8806fcac..4792ac5e 100755 --- a/examples/python/dbus/add-connection-compat.py +++ b/examples/python/dbus/add-connection-compat.py @@ -42,7 +42,7 @@ s_con = dbus.Dictionary({ 'uuid': str(uuid.uuid4()), 'id': 'MyConnectionExample'}) -addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8), ip_to_int("10.1.2.1")], signature=dbus.Signature('u')) +addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u')) s_ip4 = dbus.Dictionary({ 'addresses': dbus.Array([addr1], signature=dbus.Signature('au')), 'method': 'manual'}) @@ -56,7 +56,7 @@ con = dbus.Dictionary({ 'ipv6': s_ip6}) -print("Creating connection:", s_con['id'], "-", s_con['uuid']) +print "Creating connection:", s_con['id'], "-", s_con['uuid'] bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings") diff --git a/examples/python/dbus/add-connection.py b/examples/python/dbus/add-connection.py index 510f7c88..5ebb82a3 100755 --- a/examples/python/dbus/add-connection.py +++ b/examples/python/dbus/add-connection.py @@ -38,7 +38,7 @@ s_con = dbus.Dictionary({ addr1 = dbus.Dictionary({ 'address': '10.1.2.3', - 'prefix': dbus.UInt32(8)}) + 'prefix': dbus.UInt32(8L)}) s_ip4 = dbus.Dictionary({ 'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')), 'gateway': '10.1.2.1', @@ -53,7 +53,7 @@ con = dbus.Dictionary({ 'ipv6': s_ip6}) -print("Creating connection:", s_con['id'], "-", s_con['uuid']) +print "Creating connection:", s_con['id'], "-", s_con['uuid'] bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings") diff --git a/examples/python/dbus/add-wifi-eap-connection.py b/examples/python/dbus/add-wifi-eap-connection.py index e8ce6df9..4085ac31 100755 --- a/examples/python/dbus/add-wifi-eap-connection.py +++ b/examples/python/dbus/add-wifi-eap-connection.py @@ -20,7 +20,7 @@ import dbus, uuid def path_to_value(path): - return dbus.ByteArray("file://".encode("utf-8") + path.encode("utf-8") + "\0".encode("utf-8")) + return dbus.ByteArray("file://" + path + "\0") s_con = dbus.Dictionary({ 'type': '802-11-wireless', @@ -28,7 +28,7 @@ s_con = dbus.Dictionary({ 'id': 'My Wifi'}) s_wifi = dbus.Dictionary({ - 'ssid': dbus.ByteArray("homewifi".encode("utf-8")), + 'ssid': dbus.ByteArray("homewifi"), 'security': '802-11-wireless-security'}) s_wsec = dbus.Dictionary({'key-mgmt': 'wpa-eap'}) diff --git a/examples/python/dbus/add-wifi-psk-connection.py b/examples/python/dbus/add-wifi-psk-connection.py index d8268b1a..60cb2af9 100755 --- a/examples/python/dbus/add-wifi-psk-connection.py +++ b/examples/python/dbus/add-wifi-psk-connection.py @@ -25,7 +25,7 @@ s_con = dbus.Dictionary({ 'id': 'My-WPA-PSK'}) s_wifi = dbus.Dictionary({ - 'ssid': dbus.ByteArray("best-wifi".encode("utf-8")), + 'ssid': dbus.ByteArray("best-wifi"), 'mode': 'infrastructure', }) diff --git a/examples/python/dbus/create-bond.py b/examples/python/dbus/create-bond.py index 4600b9c2..f36426ca 100755 --- a/examples/python/dbus/create-bond.py +++ b/examples/python/dbus/create-bond.py @@ -26,7 +26,7 @@ import dbus, sys, uuid from dbus.mainloop.glib import DBusGMainLoop -from gi.repository import GObject +import gobject DBusGMainLoop(set_as_default=True) @@ -54,7 +54,7 @@ def create_bond(bond_name): 'connection': s_con, 'ipv4': s_ip4, 'ipv6': s_ip6}) - print("Creating bond connection: %s" % bond_name) + print "Creating bond connection: %s" % bond_name return add_connection(con) def create_slave(device, master): @@ -72,11 +72,11 @@ def create_slave(device, master): con = dbus.Dictionary({ '802-3-ethernet': s_wired, 'connection': s_con}) - print("Creating slave connection: %s" % slave_name) + print "Creating slave connection: %s" % slave_name add_connection(con) def usage(): - print("Usage: %s <bond_name> <ifname1> ..." % sys.argv[0]) + print "Usage: %s <bond_name> <ifname1> ..." % sys.argv[0] sys.exit(0) @@ -94,17 +94,17 @@ bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") ac = manager.ActivateConnection(bond_path, "/", "/") -print("Activating bond: %s (%s)" % (bond_name, ac)) +print "Activating bond: %s (%s)" % (bond_name, ac) # Monitor the active bond connection -loop = GObject.MainLoop() +loop = gobject.MainLoop() def properties_changed(props): if 'State' in props: if props['State'] == 2: - print("Succesfully connected") + print "Succesfully connected" loop.quit() if props['State'] == 3 or props['State'] == 4: - print("Bond activation failed") + print "Bond activation failed" loop.quit() obj = bus.get_object("org.freedesktop.NetworkManager", ac) diff --git a/examples/python/dbus/get-active-connection-uuids.py b/examples/python/dbus/get-active-connection-uuids.py index deb38dae..6fe93d05 100755 --- a/examples/python/dbus/get-active-connection-uuids.py +++ b/examples/python/dbus/get-active-connection-uuids.py @@ -49,8 +49,8 @@ for a in active: c_proxy = bus.get_object("org.freedesktop.NetworkManager", connection_path) connection = dbus.Interface(c_proxy, "org.freedesktop.NetworkManager.Settings.Connection") settings = connection.GetSettings() - print("%s (%s) - %s" % (settings['connection']['id'], uuid, settings['connection']['type'])) + print "%s (%s) - %s" % (settings['connection']['id'], uuid, settings['connection']['type']) if len(active) == 0: - print("No active connections") + print "No active connections" diff --git a/examples/python/dbus/is-wwan-default.py b/examples/python/dbus/is-wwan-default.py index 10ae31fc..a4a3ff8e 100755 --- a/examples/python/dbus/is-wwan-default.py +++ b/examples/python/dbus/is-wwan-default.py @@ -36,7 +36,7 @@ bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") busdaemon = dbus.Interface(proxy, "org.freedesktop.DBus") if not busdaemon.NameHasOwner(NM_SERVICE_NAME): - print("NetworkManager not running") + print "NetworkManager not running" sys.exit(1) # Get a proxy for the NetworkManager object @@ -46,11 +46,11 @@ props = dbus.Interface(proxy, DBUS_PROPS_IFACE) def found_connection_type(ctype): if ctype == '': - print("No active connection") + print "No active connection" elif ctype in ["gsm", "cdma", "bluetooth"]: - print("WWAN is default") + print "WWAN is default" else: - print("WWAN is not default") + print "WWAN is not default" sys.exit(0) # Shortcut #1, for NM 1.0 @@ -94,7 +94,7 @@ for a in active: break if default_is_wwan: - print("WWAN is default") + print "WWAN is default" else: - print("WWAN is not default") + print "WWAN is not default" diff --git a/examples/python/dbus/list-connections.py b/examples/python/dbus/list-connections.py index 90aec3b3..120b744a 100755 --- a/examples/python/dbus/list-connections.py +++ b/examples/python/dbus/list-connections.py @@ -35,7 +35,7 @@ def merge_secrets(proxy, config, setting_name): for setting in secrets: for key in secrets[setting]: config[setting_name][key] = secrets[setting][key] - except Exception as e: + except Exception, e: pass def dict_to_string(d, indent): @@ -64,9 +64,9 @@ def dict_to_string(d, indent): def connection_to_string(config): # dump a connection configuration to a the console for setting_name in config: - print(" Setting: %s" % setting_name) - print(dict_to_string(config[setting_name], " ")) - print("") + print " Setting: %s" % setting_name + print dict_to_string(config[setting_name], " ") + print "" def print_connections(): @@ -95,13 +95,13 @@ def print_connections(): # Get the details of the 'connection' setting s_con = config['connection'] - print(" name: %s" % s_con['id']) - print(" uuid: %s" % s_con['uuid']) - print(" type: %s" % s_con['type']) - print(" ------------------------------------------") + print " name: %s" % s_con['id'] + print " uuid: %s" % s_con['uuid'] + print " type: %s" % s_con['type'] + print " ------------------------------------------" connection_to_string(config) - print("") + print "" print_connections() diff --git a/examples/python/dbus/list-devices.py b/examples/python/dbus/list-devices.py index 1afb5a45..f35a8c8a 100755 --- a/examples/python/dbus/list-devices.py +++ b/examples/python/dbus/list-devices.py @@ -69,20 +69,20 @@ for d in devices: dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") props = prop_iface.GetAll("org.freedesktop.NetworkManager.Device") - print("============================") + print "============================" - print("Interface: %s" % props['Interface']) - try: + print "Interface: %s" % props['Interface'] + try: devtype = devtypes[props['DeviceType']] except KeyError: devtype = "Unknown" - print("Type: %s" % devtype) + print "Type: %s" % devtype - print("Driver: %s" % props['Driver']) + print "Driver: %s" % props['Driver'] try: state = states[props['State']] except KeyError: state = "Unknown" - print("State: %s" % state) + print "State: %s" % state diff --git a/examples/python/dbus/nm-state.py b/examples/python/dbus/nm-state.py index 68979efa..176090f7 100755 --- a/examples/python/dbus/nm-state.py +++ b/examples/python/dbus/nm-state.py @@ -69,9 +69,9 @@ for d in devices: # and print them out if state == 100 : # activated - print("Device %s is activated" % name) + print "Device %s is activated" % name else: - print("Device %s is not activated (state=%s)" % (name, device_states[state])) + print "Device %s is not activated (state=%s)" % (name, device_states[state]) # Get active connection state @@ -91,4 +91,4 @@ for a in active: con_details = con_iface.GetSettings() con_name = con_details['connection']['id'] - print("Connection '%s' is %s" % (con_name, connectivity_states[state].lower())) + print "Connection '%s' is %s" % (con_name, connectivity_states[state].lower()) diff --git a/examples/python/dbus/show-bssids.py b/examples/python/dbus/show-bssids.py index 9776864f..505e3d35 100755 --- a/examples/python/dbus/show-bssids.py +++ b/examples/python/dbus/show-bssids.py @@ -32,7 +32,7 @@ manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") all_aps = [] -print("Associated APs:") +print "Associated APs:" # Get all network devices devices = manager.GetDevices() @@ -69,10 +69,10 @@ for d in devices: # Print the current AP's BSSID if path == connected_path: - print("%s (%s)" % (bssid, iface)) + print "%s (%s)" % (bssid, iface) # and print out all APs the wifi devices can see -print("\nFound APs:") +print"\nFound APs:" for bssid in all_aps: - print(bssid) + print bssid diff --git a/examples/python/dbus/update-ip4-method.py b/examples/python/dbus/update-ip4-method.py index 505e808b..28a22289 100755 --- a/examples/python/dbus/update-ip4-method.py +++ b/examples/python/dbus/update-ip4-method.py @@ -31,12 +31,12 @@ import dbus, sys if len(sys.argv) < 3: - print("Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0]) + print "Usage: %s <uuid> <auto|static> [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])) + print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) sys.exit(1) # Convert method to NM method diff --git a/examples/python/dbus/update-secrets.py b/examples/python/dbus/update-secrets.py index 1fc73209..13cac1b0 100755 --- a/examples/python/dbus/update-secrets.py +++ b/examples/python/dbus/update-secrets.py @@ -22,7 +22,7 @@ # Update() method. The method replaces all previous settings with new ones # including possible secrets. # So, we get all settings using GetSettings() and then find out what secrets -# are associated with the connection using GetSecrets(), ask for new secret +# are associated with the connection using GetSecrets(), ask for new secret # values, and add them to the settings that we pass to Update(). # @@ -37,16 +37,16 @@ def change_secrets_in_one_setting(proxy, config, setting_name): # returns a dict of dicts mapping name::setting, where setting is a dict # mapping key::value. Each member of the 'setting' dict is a secret secrets = proxy.GetSecrets(setting_name) - print("Current secrets:" + secrets) + print "Current secrets:", secrets # Ask user for new secrets and put them into our connection config for setting in secrets: for key in secrets[setting]: new_secret = raw_input ("Enter new secret for '%s' in '%s': " % (key, setting)) config[setting_name][key] = new_secret - except Exception as e: + except Exception, e: #code = str(e).split(':')[0] - #print("Exception:" + str(e)) + #print "Exception:", str(e) pass def change_secrets(con_path, config): @@ -76,7 +76,7 @@ def find_connection(name): connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection") try: config = connection.GetSettings() - except Exception as e: + except Exception, e: pass # Find connection by the id @@ -101,10 +101,10 @@ if len(sys.argv) != 2: # Find the connection con = find_connection(sys.argv[1]) -print("Connection found: " + con_path) +print "Connection found: ", con_path if con: - # Obtain new secrets and put then into connection dict + # Obtain new secrets and put then into connection dict change_secrets(con_path, con) # Change the connection with Update() diff --git a/examples/python/dbus/vpn.py b/examples/python/dbus/vpn.py index a21b82ff..d60e470e 100755 --- a/examples/python/dbus/vpn.py +++ b/examples/python/dbus/vpn.py @@ -61,7 +61,7 @@ def list_uuids(): 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'])) + print "%s - %s (%s)" % (conn['uuid'], conn['id'], conn['type']) def get_active_connection_path(uuid): @@ -102,7 +102,7 @@ def get_wifi_device_path(): def activate_connection(connection_path, device_path): def reply_handler(opath): - print("Success: device activating") + print "Success: device activating" sys.exit(0) def error_handler(*args): @@ -114,7 +114,7 @@ def activate_connection(connection_path, device_path): iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager') iface.ActivateConnection('org.freedesktop.NetworkManager', connection_path, - device_path, + device_path, "/", reply_handler=reply_handler, error_handler=error_handler) @@ -126,26 +126,26 @@ if UID != 0: # Are we configured? if not len(CONNECTION_UUID): - print("missing connection UUID") + print "missing connection UUID" sys.exit(0) connection_path = get_connection_by_uuid(CONNECTION_UUID) if not connection_path: # Configured VPN connection is not known to NM, check CONNECTION_UUID. - print("couldn't find the connection") + print "couldn't find the connection" sys.exit(1) device_path = get_wifi_device_path() if not device_path: - print("no wifi device found") + print "no wifi device found" sys.exit(1) # Is it already activated? if get_active_connection_path(CONNECTION_UUID): - print("already connected") + print "already connected" sys.exit(0) -print("Activating connection...") +print "Activating connection..." activate_connection(connection_path, device_path) loop = gobject.MainLoop() loop.run() diff --git a/examples/python/dbus/wifi-active-ap.py b/examples/python/dbus/wifi-active-ap.py index c0ed6710..3b17c6f1 100755 --- a/examples/python/dbus/wifi-active-ap.py +++ b/examples/python/dbus/wifi-active-ap.py @@ -32,7 +32,7 @@ proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings") settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings") if len(sys.argv) != 2: - print("Usage: %s <ifname>" % sys.argv[0]) + print "Usage: %s <ifname>" % sys.argv[0] sys.exit(0) # Get the device object path based on interface name @@ -46,7 +46,7 @@ proxy = bus.get_object(service_name, devpath) props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties") active_ap_path = props.Get("org.freedesktop.NetworkManager.Device.Wireless", "ActiveAccessPoint") if active_ap_path == "/": - print("%s is not currently associated" % sys.argv[1]) + print "%s is not currently associated" % sys.argv[1] sys.exit(0) # Get the active access point's SSID and BSSID @@ -60,7 +60,7 @@ ssid = "" for c in raw_ssid: ssid = ssid + chr(c) -print("%s is associated to '%s' (%s)" % (sys.argv[1], ssid, bssid)) +print "%s is associated to '%s' (%s)" % (sys.argv[1], ssid, bssid) sys.exit(0) diff --git a/examples/python/dbus/wifi-hotspot.py b/examples/python/dbus/wifi-hotspot.py index 9b057a2c..10958af8 100755 --- a/examples/python/dbus/wifi-hotspot.py +++ b/examples/python/dbus/wifi-hotspot.py @@ -34,7 +34,7 @@ s_con = dbus.Dictionary({ 'id': 'Test Hotspot'}) s_wifi = dbus.Dictionary({ - 'ssid': dbus.ByteArray("My Hotspot".encode("utf-8")), + 'ssid': dbus.ByteArray("My Hotspot"), 'mode': "ap", 'band': "bg", 'channel': dbus.UInt32(1)}) @@ -54,8 +54,8 @@ con = dbus.Dictionary({ 'ipv6': s_ip6 }) -def usage(): - print("Usage: %s <ifname> [up|down]" % sys.argv[0]) +def usage(): + print "Usage: %s <ifname> [up|down]" % sys.argv[0] sys.exit(0) bus = dbus.SystemBus() @@ -99,10 +99,10 @@ if operation == "up": while time.time() < start + 10: state = active_props.Get("org.freedesktop.NetworkManager.Connection.Active", "State") if state == 2: # NM_ACTIVE_CONNECTION_STATE_ACTIVATED - print("Access point started") + print "Access point started" sys.exit(0) time.sleep(1) - print("Failed to start access point") + print "Failed to start access point" elif operation == "down": device.Disconnect() else: diff --git a/examples/python/gi/add_connection.py b/examples/python/gi/add_connection.py index f5b5e63c..cfb40a9a 100755 --- a/examples/python/gi/add_connection.py +++ b/examples/python/gi/add_connection.py @@ -37,7 +37,7 @@ import sys, uuid main_loop = None def print_values(setting, key, value, flags, data): - print(" %s.%s: %s" % (setting.get_name(), key, value)) + print " %s.%s: %s" % (setting.get_name(), key, value) # create an Ethernet connection and return it def create_profile(name): @@ -70,7 +70,7 @@ def added_cb(client, result, data): try: client.add_connection_finish(result) print("The connection profile has been succesfully added to NetworkManager.") - except Exception as e: + except Exception, e: sys.stderr.write("Error: %s\n" % e) main_loop.quit() diff --git a/examples/python/gi/deactivate-all.py b/examples/python/gi/deactivate-all.py index a4588522..59842ac2 100755 --- a/examples/python/gi/deactivate-all.py +++ b/examples/python/gi/deactivate-all.py @@ -78,6 +78,6 @@ if __name__ == "__main__": try: client.deactivate_connection(ac, None) sys.stdout.write("\033[32m -> succeeded\033[0m\n") - except Exception as e: + except Exception, e: sys.stderr.write("\033[31m -> failed\033[0m (%s)\n" % e.message) diff --git a/examples/python/gi/device-state-ip4config.py b/examples/python/gi/device-state-ip4config.py index b92a7b09..2a4a6221 100755 --- a/examples/python/gi/device-state-ip4config.py +++ b/examples/python/gi/device-state-ip4config.py @@ -27,22 +27,22 @@ from gi.repository import GLib, NM # # This example shows how to get NMIP4Config from NMDevice after it is activated. -# +# # We listen to notify::ip4-config glib signal. This signal is trigered by D-Bus # PropertiesChanged for IP4Config that comes after StateChanged for NMDevice. # main_loop = None - + def do_notify(self, property): - print("notify: %s" % property) + print "notify: %s" % property ip4cfg = self.get_ip4_config() if ip4cfg is not None: - print("ip4-config: %s" % ip4cfg.get_path()) + print "ip4-config: %s" % ip4cfg.get_path() main_loop.quit() def state_changed(obj, arg1, arg2, arg3): - print("State changed: New: %d, Old: %d, Reason: %d" % (arg1, arg2, arg3)) + print "State changed: New: %d, Old: %d, Reason: %d" % (arg1, arg2, arg3) # Device is connected if arg1 == 100: obj.connect('notify::ip4-config', do_notify) @@ -57,8 +57,8 @@ if __name__ == "__main__": dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) - print("Device: %s - %s" % (dev_iface, dev.get_device_type().value_name)) - print("---------------------------------------") + print "Device: %s - %s" % (dev_iface, dev.get_device_type().value_name) + print "---------------------------------------" dev.connect('state-changed', state_changed) main_loop = GLib.MainLoop() diff --git a/examples/python/gi/get-active-connections.py b/examples/python/gi/get-active-connections.py index cee579f9..22c9eb4a 100755 --- a/examples/python/gi/get-active-connections.py +++ b/examples/python/gi/get-active-connections.py @@ -29,8 +29,8 @@ if __name__ == "__main__": 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())) + print "%s (%s) - %s" % (ac.get_id(), ac.get_uuid(), ac.get_connection_type()) if len(acons) == 0: - print("No active connections") + print "No active connections" diff --git a/examples/python/gi/get_ips.py b/examples/python/gi/get_ips.py index 66d154f2..77e1d171 100755 --- a/examples/python/gi/get_ips.py +++ b/examples/python/gi/get_ips.py @@ -116,8 +116,8 @@ if __name__ == "__main__": dev = c.get_device_by_iface(dev_iface) if dev is None: sys.exit('Device \'%s\' not found' % dev_iface) - print("Device: %s - %s" % (dev_iface, dev.get_device_type().value_name)) - print("---------------------------------------") + print "Device: %s - %s" % (dev_iface, dev.get_device_type().value_name) + print "---------------------------------------" print("IPv4 addresses:") print("---------------") @@ -134,7 +134,7 @@ if __name__ == "__main__": show_routes(dev, socket.AF_INET) print - print("IPv6 addresses:") + print "IPv6 addresses:" print("---------------") show_addresses(dev, socket.AF_INET6) print @@ -144,17 +144,17 @@ if __name__ == "__main__": show_gateway(dev, socket.AF_INET6) print - print("IPv6 routes:") + print "IPv6 routes:" print("------------") show_routes(dev, socket.AF_INET6) print - print("IPv4 DNS:") + print "IPv4 DNS:" print("------------") show_dns(dev, socket.AF_INET) print - print("IPv6 DNS:") + print "IPv6 DNS:" print("------------") show_dns(dev, socket.AF_INET6) print diff --git a/examples/python/gi/list-connections.py b/examples/python/gi/list-connections.py index 2139e8c1..32ea70f5 100755 --- a/examples/python/gi/list-connections.py +++ b/examples/python/gi/list-connections.py @@ -27,7 +27,7 @@ from gi.repository import NM # This example asks settings service for all configured connections. def print_values(setting, key, value, flags, data): - print(" %s.%s: %s" % (setting.get_name(), key, value)) + print " %s.%s: %s" % (setting.get_name(), key, value) if __name__ == "__main__": # create Client object @@ -38,7 +38,7 @@ if __name__ == "__main__": # 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") + print "\n" diff --git a/examples/python/gi/show-wifi-networks.py b/examples/python/gi/show-wifi-networks.py index 4c7a126f..db49b555 100755 --- a/examples/python/gi/show-wifi-networks.py +++ b/examples/python/gi/show-wifi-networks.py @@ -49,8 +49,8 @@ def print_device_info(device): if active_ap is not None: 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)) + print info + print '=' * len(info) def mode_to_string(mode): if mode == getattr(NM, '80211Mode').INFRA: @@ -114,16 +114,16 @@ def print_ap_info(ap): flags = ap.get_flags() wpa_flags = ap.get_wpa_flags() rsn_flags = ap.get_rsn_flags() - print("SSID: %s" % (ssid_to_utf8(ap))) - print("BSSID: %s" % (ap.get_bssid())) - print("Frequency: %s" % (frequency)) - print("Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency))) - print("Mode: %s" % (mode_to_string(ap.get_mode()))) - print("Flags: %s" % (flags_to_string(flags))) - print("WPA flags: %s" % (security_flags_to_string(wpa_flags))) - print("RSN flags: %s" % (security_flags_to_string(rsn_flags))) - print("Security: %s" % (flags_to_security(flags, wpa_flags, rsn_flags))) - print("Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength)) + print "SSID: %s" % (ssid_to_utf8(ap)) + print "BSSID: %s" % (ap.get_bssid()) + print "Frequency: %s" % (frequency) + print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency)) + print "Mode: %s" % (mode_to_string(ap.get_mode())) + print "Flags: %s" % (flags_to_string(flags)) + print "WPA flags: %s" % (security_flags_to_string(wpa_flags)) + print "RSN flags: %s" % (security_flags_to_string(rsn_flags)) + print "Security: %s" % (flags_to_security(flags, wpa_flags, rsn_flags)) + print "Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength) print if __name__ == "__main__": diff --git a/examples/python/gi/update-ip4-method.py b/examples/python/gi/update-ip4-method.py index 3b2df72e..12124599 100755 --- a/examples/python/gi/update-ip4-method.py +++ b/examples/python/gi/update-ip4-method.py @@ -35,12 +35,12 @@ import sys, socket if __name__ == "__main__": # parse and validate arguments if len(sys.argv) < 3: - print("Usage: %s <uuid> <auto|static> [address prefix gateway]" % sys.argv[0]) + print "Usage: %s <uuid> <auto|static> [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])) + print "Usage: %s %s static address prefix [gateway]" % (sys.argv[0], sys.argv[1]) sys.exit(1) uuid = sys.argv[1] @@ -81,7 +81,7 @@ if __name__ == "__main__": try: c.commit_changes(True, None) print("The connection profile has been updated.") - except Exception as e: + except Exception, e: sys.stderr.write("Error: %s\n" % e) break diff --git a/examples/python/nmex.py b/examples/python/nmex.py deleted file mode 100644 index a85eecaf..00000000 --- a/examples/python/nmex.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/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 -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Copyright 2018 Red Hat, Inc. - -############################################################################### -# nmex.py contains helper functions used by some examples. The helper functions -# should be simple and independent, so that the user can extract them easily -# when modifying the example to his needs. -############################################################################### - -def _sys_clock_gettime_ns_lazy(): - import ctypes - - class timespec(ctypes.Structure): - _fields_ = [ - ('tv_sec', ctypes.c_long), - ('tv_nsec', ctypes.c_long) - ] - - librt = ctypes.CDLL('librt.so.1', use_errno=True) - clock_gettime = librt.clock_gettime - clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)] - - t = timespec() - def f(clock_id): - if clock_gettime(clock_id, ctypes.pointer(t)) != 0: - import os - errno_ = ctypes.get_errno() - raise OSError(errno_, os.strerror(errno_)) - return (t.tv_sec * 1000000000) + t.tv_nsec - return f - -_sys_clock_gettime_ns = None - -# call POSIX clock_gettime() and return it as integer (in nanoseconds) -def sys_clock_gettime_ns(clock_id): - global _sys_clock_gettime_ns - if _sys_clock_gettime_ns is None: - _sys_clock_gettime_ns = _sys_clock_gettime_ns_lazy() - return _sys_clock_gettime_ns(clock_id) - -def nm_boot_time_ns(): - # NetworkManager exposes some timestamps as CLOCK_BOOTTIME. - # Try that first (number 7). - try: - return sys_clock_gettime_ns(7) - except OSError as e: - # On systems, where this is not available, fallback to - # CLOCK_MONOTONIC (numeric 1). - # That is what NetworkManager does as well. - import errno - if e.errno == errno.EINVAL: - return sys_clock_gettime_ns(1) - raise -def nm_boot_time_us(): - return nm_boot_time_ns() / 1000 -def nm_boot_time_ms(): - return nm_boot_time_ns() / 1000000 -def nm_boot_time_s(): - return nm_boot_time_ns() / 1000000000 - -############################################################################### diff --git a/examples/shell/nm-logging.sh b/examples/shell/nm-logging.sh index 0988e55e..afd06e5a 100755 --- a/examples/shell/nm-logging.sh +++ b/examples/shell/nm-logging.sh @@ -23,7 +23,7 @@ # Sets NM logging level and/or domains (see description in 'man NetworkManager.conf') # The level controls how verbose NM's log output will be (err,warn,info,debug). # Domains control what parts of networking NM emits log messages for. Leaving -# either of the two arguments blank (i.e., an empty string) will leave that +# either of the two arguments blank (i.e., an empty string) will leave that # parameter unchanged. # # The normal logging level is 'info', for debugging use 'debug'. |