diff options
| author | Yifan J <yfjiang@suse.com> | 2017-12-02 12:44:50 +0800 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2017-12-04 11:21:40 +0100 |
| commit | 797d9c4403cf170870e9d7d9b0ea22317c850b35 (patch) | |
| tree | 2ef6f3ed5bd002d958ce1231c061c667ccda0d5e /examples/python/dbus | |
| parent | 5e239d2c04728250e4cc2eb36b2005333cfac810 (diff) | |
| download | NetworkManager-797d9c4403cf170870e9d7d9b0ea22317c850b35.tar.gz | |
python: make dbus, gi examples, and debug-helper.py python3 ready
https://bugzilla.gnome.org/show_bug.cgi?id=791121
Diffstat (limited to 'examples/python/dbus')
| -rwxr-xr-x | examples/python/dbus/add-connection-compat.py | 4 | ||||
| -rwxr-xr-x | examples/python/dbus/add-connection.py | 4 | ||||
| -rwxr-xr-x | examples/python/dbus/add-wifi-eap-connection.py | 4 | ||||
| -rwxr-xr-x | examples/python/dbus/add-wifi-psk-connection.py | 2 | ||||
| -rwxr-xr-x | examples/python/dbus/create-bond.py | 16 | ||||
| -rwxr-xr-x | examples/python/dbus/get-active-connection-uuids.py | 4 | ||||
| -rwxr-xr-x | examples/python/dbus/is-wwan-default.py | 12 | ||||
| -rwxr-xr-x | examples/python/dbus/list-connections.py | 18 | ||||
| -rwxr-xr-x | examples/python/dbus/list-devices.py | 10 | ||||
| -rwxr-xr-x | examples/python/dbus/nm-state.py | 6 | ||||
| -rwxr-xr-x | examples/python/dbus/show-bssids.py | 8 | ||||
| -rwxr-xr-x | examples/python/dbus/update-ip4-method.py | 4 | ||||
| -rwxr-xr-x | examples/python/dbus/update-secrets.py | 10 | ||||
| -rwxr-xr-x | examples/python/dbus/vpn.py | 14 | ||||
| -rwxr-xr-x | examples/python/dbus/wifi-active-ap.py | 6 | ||||
| -rwxr-xr-x | examples/python/dbus/wifi-hotspot.py | 8 |
16 files changed, 65 insertions, 65 deletions
diff --git a/examples/python/dbus/add-connection-compat.py b/examples/python/dbus/add-connection-compat.py index 4792ac5eb6..8806fcac1c 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(8L), ip_to_int("10.1.2.1")], signature=dbus.Signature('u')) +addr1 = dbus.Array([ip_to_int("10.1.2.3"), dbus.UInt32(8), 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 5ebb82a38b..510f7c88a7 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(8L)}) + 'prefix': dbus.UInt32(8)}) 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 4085ac31a3..e8ce6df96b 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://" + path + "\0") + return dbus.ByteArray("file://".encode("utf-8") + path.encode("utf-8") + "\0".encode("utf-8")) 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"), + 'ssid': dbus.ByteArray("homewifi".encode("utf-8")), '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 60cb2af927..d8268b1a56 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"), + 'ssid': dbus.ByteArray("best-wifi".encode("utf-8")), 'mode': 'infrastructure', }) diff --git a/examples/python/dbus/create-bond.py b/examples/python/dbus/create-bond.py index f36426ca41..4600b9c222 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 -import gobject +from gi.repository 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 6fe93d05da..deb38dae4d 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 a4a3ff8e71..10ae31fc9d 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 120b744acc..90aec3b389 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, e: + except Exception as 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 f35a8c8a02..84ece38ab6 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'] + 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 176090f7c7..68979efa5e 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 505e3d35c7..9776864f45 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 28a222899b..505e808bee 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 13cac1b08c..3a51446bd7 100755 --- a/examples/python/dbus/update-secrets.py +++ b/examples/python/dbus/update-secrets.py @@ -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, e: + except Exception as 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, e: + except Exception as e: pass # Find connection by the id @@ -101,7 +101,7 @@ 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 diff --git a/examples/python/dbus/vpn.py b/examples/python/dbus/vpn.py index d60e470e05..ceaf6b9740 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): @@ -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 3b17c6f130..c0ed67109b 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 10958af86c..dd33b4459f 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"), + 'ssid': dbus.ByteArray("My Hotspot".encode("utf-8")), 'mode': "ap", 'band': "bg", 'channel': dbus.UInt32(1)}) @@ -55,7 +55,7 @@ con = dbus.Dictionary({ }) def usage(): - print "Usage: %s <ifname> [up|down]" % sys.argv[0] + 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: |
