python: make dbus, gi examples, and debug-helper.py python3 ready
https://bugzilla.gnome.org/show_bug.cgi?id=791121
This commit is contained in:
@@ -42,7 +42,7 @@ s_con = dbus.Dictionary({
|
|||||||
'uuid': str(uuid.uuid4()),
|
'uuid': str(uuid.uuid4()),
|
||||||
'id': 'MyConnectionExample'})
|
'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({
|
s_ip4 = dbus.Dictionary({
|
||||||
'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
|
'addresses': dbus.Array([addr1], signature=dbus.Signature('au')),
|
||||||
'method': 'manual'})
|
'method': 'manual'})
|
||||||
@@ -56,7 +56,7 @@ con = dbus.Dictionary({
|
|||||||
'ipv6': s_ip6})
|
'ipv6': s_ip6})
|
||||||
|
|
||||||
|
|
||||||
print "Creating connection:", s_con['id'], "-", s_con['uuid']
|
print("Creating connection:", s_con['id'], "-", s_con['uuid'])
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
|
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
|
||||||
|
@@ -38,7 +38,7 @@ s_con = dbus.Dictionary({
|
|||||||
|
|
||||||
addr1 = dbus.Dictionary({
|
addr1 = dbus.Dictionary({
|
||||||
'address': '10.1.2.3',
|
'address': '10.1.2.3',
|
||||||
'prefix': dbus.UInt32(8L)})
|
'prefix': dbus.UInt32(8)})
|
||||||
s_ip4 = dbus.Dictionary({
|
s_ip4 = dbus.Dictionary({
|
||||||
'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')),
|
'address-data': dbus.Array([addr1], signature=dbus.Signature('a{sv}')),
|
||||||
'gateway': '10.1.2.1',
|
'gateway': '10.1.2.1',
|
||||||
@@ -53,7 +53,7 @@ con = dbus.Dictionary({
|
|||||||
'ipv6': s_ip6})
|
'ipv6': s_ip6})
|
||||||
|
|
||||||
|
|
||||||
print "Creating connection:", s_con['id'], "-", s_con['uuid']
|
print("Creating connection:", s_con['id'], "-", s_con['uuid'])
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
|
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
import dbus, uuid
|
import dbus, uuid
|
||||||
|
|
||||||
def path_to_value(path):
|
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({
|
s_con = dbus.Dictionary({
|
||||||
'type': '802-11-wireless',
|
'type': '802-11-wireless',
|
||||||
@@ -28,7 +28,7 @@ s_con = dbus.Dictionary({
|
|||||||
'id': 'My Wifi'})
|
'id': 'My Wifi'})
|
||||||
|
|
||||||
s_wifi = dbus.Dictionary({
|
s_wifi = dbus.Dictionary({
|
||||||
'ssid': dbus.ByteArray("homewifi"),
|
'ssid': dbus.ByteArray("homewifi".encode("utf-8")),
|
||||||
'security': '802-11-wireless-security'})
|
'security': '802-11-wireless-security'})
|
||||||
|
|
||||||
s_wsec = dbus.Dictionary({'key-mgmt': 'wpa-eap'})
|
s_wsec = dbus.Dictionary({'key-mgmt': 'wpa-eap'})
|
||||||
|
@@ -25,7 +25,7 @@ s_con = dbus.Dictionary({
|
|||||||
'id': 'My-WPA-PSK'})
|
'id': 'My-WPA-PSK'})
|
||||||
|
|
||||||
s_wifi = dbus.Dictionary({
|
s_wifi = dbus.Dictionary({
|
||||||
'ssid': dbus.ByteArray("best-wifi"),
|
'ssid': dbus.ByteArray("best-wifi".encode("utf-8")),
|
||||||
'mode': 'infrastructure',
|
'mode': 'infrastructure',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
import dbus, sys, uuid
|
import dbus, sys, uuid
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
import gobject
|
from gi.repository import GObject
|
||||||
|
|
||||||
DBusGMainLoop(set_as_default=True)
|
DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ def create_bond(bond_name):
|
|||||||
'connection': s_con,
|
'connection': s_con,
|
||||||
'ipv4': s_ip4,
|
'ipv4': s_ip4,
|
||||||
'ipv6': s_ip6})
|
'ipv6': s_ip6})
|
||||||
print "Creating bond connection: %s" % bond_name
|
print("Creating bond connection: %s" % bond_name)
|
||||||
return add_connection(con)
|
return add_connection(con)
|
||||||
|
|
||||||
def create_slave(device, master):
|
def create_slave(device, master):
|
||||||
@@ -72,11 +72,11 @@ def create_slave(device, master):
|
|||||||
con = dbus.Dictionary({
|
con = dbus.Dictionary({
|
||||||
'802-3-ethernet': s_wired,
|
'802-3-ethernet': s_wired,
|
||||||
'connection': s_con})
|
'connection': s_con})
|
||||||
print "Creating slave connection: %s" % slave_name
|
print("Creating slave connection: %s" % slave_name)
|
||||||
add_connection(con)
|
add_connection(con)
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "Usage: %s <bond_name> <ifname1> ..." % sys.argv[0]
|
print("Usage: %s <bond_name> <ifname1> ..." % sys.argv[0])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
@@ -94,17 +94,17 @@ bus = dbus.SystemBus()
|
|||||||
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
|
proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
|
||||||
manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
|
manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
|
||||||
ac = manager.ActivateConnection(bond_path, "/", "/")
|
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
|
# Monitor the active bond connection
|
||||||
loop = gobject.MainLoop()
|
loop = GObject.MainLoop()
|
||||||
def properties_changed(props):
|
def properties_changed(props):
|
||||||
if 'State' in props:
|
if 'State' in props:
|
||||||
if props['State'] == 2:
|
if props['State'] == 2:
|
||||||
print "Succesfully connected"
|
print("Succesfully connected")
|
||||||
loop.quit()
|
loop.quit()
|
||||||
if props['State'] == 3 or props['State'] == 4:
|
if props['State'] == 3 or props['State'] == 4:
|
||||||
print "Bond activation failed"
|
print("Bond activation failed")
|
||||||
loop.quit()
|
loop.quit()
|
||||||
|
|
||||||
obj = bus.get_object("org.freedesktop.NetworkManager", ac)
|
obj = bus.get_object("org.freedesktop.NetworkManager", ac)
|
||||||
|
@@ -49,8 +49,8 @@ for a in active:
|
|||||||
c_proxy = bus.get_object("org.freedesktop.NetworkManager", connection_path)
|
c_proxy = bus.get_object("org.freedesktop.NetworkManager", connection_path)
|
||||||
connection = dbus.Interface(c_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
connection = dbus.Interface(c_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
||||||
settings = connection.GetSettings()
|
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:
|
if len(active) == 0:
|
||||||
print "No active connections"
|
print("No active connections")
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ bus = dbus.SystemBus()
|
|||||||
proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
proxy = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
||||||
busdaemon = dbus.Interface(proxy, "org.freedesktop.DBus")
|
busdaemon = dbus.Interface(proxy, "org.freedesktop.DBus")
|
||||||
if not busdaemon.NameHasOwner(NM_SERVICE_NAME):
|
if not busdaemon.NameHasOwner(NM_SERVICE_NAME):
|
||||||
print "NetworkManager not running"
|
print("NetworkManager not running")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Get a proxy for the NetworkManager object
|
# Get a proxy for the NetworkManager object
|
||||||
@@ -46,11 +46,11 @@ props = dbus.Interface(proxy, DBUS_PROPS_IFACE)
|
|||||||
|
|
||||||
def found_connection_type(ctype):
|
def found_connection_type(ctype):
|
||||||
if ctype == '':
|
if ctype == '':
|
||||||
print "No active connection"
|
print("No active connection")
|
||||||
elif ctype in ["gsm", "cdma", "bluetooth"]:
|
elif ctype in ["gsm", "cdma", "bluetooth"]:
|
||||||
print "WWAN is default"
|
print("WWAN is default")
|
||||||
else:
|
else:
|
||||||
print "WWAN is not default"
|
print("WWAN is not default")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Shortcut #1, for NM 1.0
|
# Shortcut #1, for NM 1.0
|
||||||
@@ -94,7 +94,7 @@ for a in active:
|
|||||||
break
|
break
|
||||||
|
|
||||||
if default_is_wwan:
|
if default_is_wwan:
|
||||||
print "WWAN is default"
|
print("WWAN is default")
|
||||||
else:
|
else:
|
||||||
print "WWAN is not default"
|
print("WWAN is not default")
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ def merge_secrets(proxy, config, setting_name):
|
|||||||
for setting in secrets:
|
for setting in secrets:
|
||||||
for key in secrets[setting]:
|
for key in secrets[setting]:
|
||||||
config[setting_name][key] = secrets[setting][key]
|
config[setting_name][key] = secrets[setting][key]
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def dict_to_string(d, indent):
|
def dict_to_string(d, indent):
|
||||||
@@ -64,9 +64,9 @@ def dict_to_string(d, indent):
|
|||||||
def connection_to_string(config):
|
def connection_to_string(config):
|
||||||
# dump a connection configuration to a the console
|
# dump a connection configuration to a the console
|
||||||
for setting_name in config:
|
for setting_name in config:
|
||||||
print " Setting: %s" % setting_name
|
print(" Setting: %s" % setting_name)
|
||||||
print dict_to_string(config[setting_name], " ")
|
print(dict_to_string(config[setting_name], " "))
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
|
|
||||||
def print_connections():
|
def print_connections():
|
||||||
@@ -95,13 +95,13 @@ def print_connections():
|
|||||||
|
|
||||||
# Get the details of the 'connection' setting
|
# Get the details of the 'connection' setting
|
||||||
s_con = config['connection']
|
s_con = config['connection']
|
||||||
print " name: %s" % s_con['id']
|
print(" name: %s" % s_con['id'])
|
||||||
print " uuid: %s" % s_con['uuid']
|
print(" uuid: %s" % s_con['uuid'])
|
||||||
print " type: %s" % s_con['type']
|
print(" type: %s" % s_con['type'])
|
||||||
print " ------------------------------------------"
|
print(" ------------------------------------------")
|
||||||
connection_to_string(config)
|
connection_to_string(config)
|
||||||
|
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
print_connections()
|
print_connections()
|
||||||
|
|
||||||
|
@@ -69,20 +69,20 @@ for d in devices:
|
|||||||
dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
|
dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
|
||||||
prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties")
|
prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties")
|
||||||
props = prop_iface.GetAll("org.freedesktop.NetworkManager.Device")
|
props = prop_iface.GetAll("org.freedesktop.NetworkManager.Device")
|
||||||
print "============================"
|
print("============================")
|
||||||
|
|
||||||
print "Interface: %s" % props['Interface']
|
print("Interface: %s" % props['Interface'])
|
||||||
try:
|
try:
|
||||||
devtype = devtypes[props['DeviceType']]
|
devtype = devtypes[props['DeviceType']]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
devtype = "Unknown"
|
devtype = "Unknown"
|
||||||
print "Type: %s" % devtype
|
print("Type: %s" % devtype)
|
||||||
|
|
||||||
print "Driver: %s" % props['Driver']
|
print("Driver: %s" % props['Driver'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
state = states[props['State']]
|
state = states[props['State']]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
state = "Unknown"
|
state = "Unknown"
|
||||||
print "State: %s" % state
|
print("State: %s" % state)
|
||||||
|
|
||||||
|
@@ -69,9 +69,9 @@ for d in devices:
|
|||||||
|
|
||||||
# and print them out
|
# and print them out
|
||||||
if state == 100 : # activated
|
if state == 100 : # activated
|
||||||
print "Device %s is activated" % name
|
print("Device %s is activated" % name)
|
||||||
else:
|
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
|
# Get active connection state
|
||||||
@@ -91,4 +91,4 @@ for a in active:
|
|||||||
con_details = con_iface.GetSettings()
|
con_details = con_iface.GetSettings()
|
||||||
con_name = con_details['connection']['id']
|
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()))
|
||||||
|
@@ -32,7 +32,7 @@ manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
|
|||||||
|
|
||||||
all_aps = []
|
all_aps = []
|
||||||
|
|
||||||
print "Associated APs:"
|
print("Associated APs:")
|
||||||
|
|
||||||
# Get all network devices
|
# Get all network devices
|
||||||
devices = manager.GetDevices()
|
devices = manager.GetDevices()
|
||||||
@@ -69,10 +69,10 @@ for d in devices:
|
|||||||
|
|
||||||
# Print the current AP's BSSID
|
# Print the current AP's BSSID
|
||||||
if path == connected_path:
|
if path == connected_path:
|
||||||
print "%s (%s)" % (bssid, iface)
|
print("%s (%s)" % (bssid, iface))
|
||||||
|
|
||||||
# and print out all APs the wifi devices can see
|
# and print out all APs the wifi devices can see
|
||||||
print"\nFound APs:"
|
print("\nFound APs:")
|
||||||
for bssid in all_aps:
|
for bssid in all_aps:
|
||||||
print bssid
|
print(bssid)
|
||||||
|
|
||||||
|
@@ -31,12 +31,12 @@
|
|||||||
import dbus, sys
|
import dbus, sys
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
method = sys.argv[2]
|
method = sys.argv[2]
|
||||||
if method == "static" and len(sys.argv) < 5:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Convert method to NM method
|
# Convert method to NM method
|
||||||
|
@@ -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
|
# 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
|
# mapping key::value. Each member of the 'setting' dict is a secret
|
||||||
secrets = proxy.GetSecrets(setting_name)
|
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
|
# Ask user for new secrets and put them into our connection config
|
||||||
for setting in secrets:
|
for setting in secrets:
|
||||||
for key in secrets[setting]:
|
for key in secrets[setting]:
|
||||||
new_secret = raw_input ("Enter new secret for '%s' in '%s': " % (key, setting))
|
new_secret = raw_input ("Enter new secret for '%s' in '%s': " % (key, setting))
|
||||||
config[setting_name][key] = new_secret
|
config[setting_name][key] = new_secret
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
#code = str(e).split(':')[0]
|
#code = str(e).split(':')[0]
|
||||||
#print "Exception:", str(e)
|
#print("Exception:" + str(e))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def change_secrets(con_path, config):
|
def change_secrets(con_path, config):
|
||||||
@@ -76,7 +76,7 @@ def find_connection(name):
|
|||||||
connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
connection = dbus.Interface(con_proxy, "org.freedesktop.NetworkManager.Settings.Connection")
|
||||||
try:
|
try:
|
||||||
config = connection.GetSettings()
|
config = connection.GetSettings()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Find connection by the id
|
# Find connection by the id
|
||||||
@@ -101,7 +101,7 @@ if len(sys.argv) != 2:
|
|||||||
# Find the connection
|
# Find the connection
|
||||||
con = find_connection(sys.argv[1])
|
con = find_connection(sys.argv[1])
|
||||||
|
|
||||||
print "Connection found: ", con_path
|
print("Connection found: " + con_path)
|
||||||
|
|
||||||
if con:
|
if con:
|
||||||
# Obtain new secrets and put then into connection dict
|
# Obtain new secrets and put then into connection dict
|
||||||
|
@@ -61,7 +61,7 @@ def list_uuids():
|
|||||||
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
|
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.NetworkManager.Settings.Connection')
|
||||||
settings = iface.GetSettings()
|
settings = iface.GetSettings()
|
||||||
conn = settings['connection']
|
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):
|
def get_active_connection_path(uuid):
|
||||||
@@ -102,7 +102,7 @@ def get_wifi_device_path():
|
|||||||
def activate_connection(connection_path, device_path):
|
def activate_connection(connection_path, device_path):
|
||||||
|
|
||||||
def reply_handler(opath):
|
def reply_handler(opath):
|
||||||
print "Success: device activating"
|
print("Success: device activating")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def error_handler(*args):
|
def error_handler(*args):
|
||||||
@@ -126,26 +126,26 @@ if UID != 0:
|
|||||||
|
|
||||||
# Are we configured?
|
# Are we configured?
|
||||||
if not len(CONNECTION_UUID):
|
if not len(CONNECTION_UUID):
|
||||||
print "missing connection UUID"
|
print("missing connection UUID")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
connection_path = get_connection_by_uuid(CONNECTION_UUID)
|
connection_path = get_connection_by_uuid(CONNECTION_UUID)
|
||||||
if not connection_path:
|
if not connection_path:
|
||||||
# Configured VPN connection is not known to NM, check CONNECTION_UUID.
|
# 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)
|
sys.exit(1)
|
||||||
|
|
||||||
device_path = get_wifi_device_path()
|
device_path = get_wifi_device_path()
|
||||||
if not device_path:
|
if not device_path:
|
||||||
print "no wifi device found"
|
print("no wifi device found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Is it already activated?
|
# Is it already activated?
|
||||||
if get_active_connection_path(CONNECTION_UUID):
|
if get_active_connection_path(CONNECTION_UUID):
|
||||||
print "already connected"
|
print("already connected")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
print "Activating connection..."
|
print("Activating connection...")
|
||||||
activate_connection(connection_path, device_path)
|
activate_connection(connection_path, device_path)
|
||||||
loop = gobject.MainLoop()
|
loop = gobject.MainLoop()
|
||||||
loop.run()
|
loop.run()
|
||||||
|
@@ -32,7 +32,7 @@ proxy = bus.get_object(service_name, "/org/freedesktop/NetworkManager/Settings")
|
|||||||
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
|
settings = dbus.Interface(proxy, "org.freedesktop.NetworkManager.Settings")
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print "Usage: %s <ifname>" % sys.argv[0]
|
print("Usage: %s <ifname>" % sys.argv[0])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Get the device object path based on interface name
|
# 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")
|
props = dbus.Interface(proxy, "org.freedesktop.DBus.Properties")
|
||||||
active_ap_path = props.Get("org.freedesktop.NetworkManager.Device.Wireless", "ActiveAccessPoint")
|
active_ap_path = props.Get("org.freedesktop.NetworkManager.Device.Wireless", "ActiveAccessPoint")
|
||||||
if active_ap_path == "/":
|
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)
|
sys.exit(0)
|
||||||
|
|
||||||
# Get the active access point's SSID and BSSID
|
# Get the active access point's SSID and BSSID
|
||||||
@@ -60,7 +60,7 @@ ssid = ""
|
|||||||
for c in raw_ssid:
|
for c in raw_ssid:
|
||||||
ssid = ssid + chr(c)
|
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)
|
sys.exit(0)
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ s_con = dbus.Dictionary({
|
|||||||
'id': 'Test Hotspot'})
|
'id': 'Test Hotspot'})
|
||||||
|
|
||||||
s_wifi = dbus.Dictionary({
|
s_wifi = dbus.Dictionary({
|
||||||
'ssid': dbus.ByteArray("My Hotspot"),
|
'ssid': dbus.ByteArray("My Hotspot".encode("utf-8")),
|
||||||
'mode': "ap",
|
'mode': "ap",
|
||||||
'band': "bg",
|
'band': "bg",
|
||||||
'channel': dbus.UInt32(1)})
|
'channel': dbus.UInt32(1)})
|
||||||
@@ -55,7 +55,7 @@ con = dbus.Dictionary({
|
|||||||
})
|
})
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "Usage: %s <ifname> [up|down]" % sys.argv[0]
|
print("Usage: %s <ifname> [up|down]" % sys.argv[0])
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
bus = dbus.SystemBus()
|
bus = dbus.SystemBus()
|
||||||
@@ -99,10 +99,10 @@ if operation == "up":
|
|||||||
while time.time() < start + 10:
|
while time.time() < start + 10:
|
||||||
state = active_props.Get("org.freedesktop.NetworkManager.Connection.Active", "State")
|
state = active_props.Get("org.freedesktop.NetworkManager.Connection.Active", "State")
|
||||||
if state == 2: # NM_ACTIVE_CONNECTION_STATE_ACTIVATED
|
if state == 2: # NM_ACTIVE_CONNECTION_STATE_ACTIVATED
|
||||||
print "Access point started"
|
print("Access point started")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print "Failed to start access point"
|
print("Failed to start access point")
|
||||||
elif operation == "down":
|
elif operation == "down":
|
||||||
device.Disconnect()
|
device.Disconnect()
|
||||||
else:
|
else:
|
||||||
|
@@ -37,7 +37,7 @@ import sys, uuid
|
|||||||
main_loop = None
|
main_loop = None
|
||||||
|
|
||||||
def print_values(setting, key, value, flags, data):
|
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
|
# create an Ethernet connection and return it
|
||||||
def create_profile(name):
|
def create_profile(name):
|
||||||
@@ -70,7 +70,7 @@ def added_cb(client, result, data):
|
|||||||
try:
|
try:
|
||||||
client.add_connection_finish(result)
|
client.add_connection_finish(result)
|
||||||
print("The connection profile has been succesfully added to NetworkManager.")
|
print("The connection profile has been succesfully added to NetworkManager.")
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
sys.stderr.write("Error: %s\n" % e)
|
sys.stderr.write("Error: %s\n" % e)
|
||||||
main_loop.quit()
|
main_loop.quit()
|
||||||
|
|
||||||
|
@@ -78,6 +78,6 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
client.deactivate_connection(ac, None)
|
client.deactivate_connection(ac, None)
|
||||||
sys.stdout.write("\033[32m -> succeeded\033[0m\n")
|
sys.stdout.write("\033[32m -> succeeded\033[0m\n")
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
sys.stderr.write("\033[31m -> failed\033[0m (%s)\n" % e.message)
|
sys.stderr.write("\033[31m -> failed\033[0m (%s)\n" % e.message)
|
||||||
|
|
||||||
|
@@ -35,14 +35,14 @@ from gi.repository import GLib, NM
|
|||||||
main_loop = None
|
main_loop = None
|
||||||
|
|
||||||
def do_notify(self, property):
|
def do_notify(self, property):
|
||||||
print "notify: %s" % property
|
print("notify: %s" % property)
|
||||||
ip4cfg = self.get_ip4_config()
|
ip4cfg = self.get_ip4_config()
|
||||||
if ip4cfg is not None:
|
if ip4cfg is not None:
|
||||||
print "ip4-config: %s" % ip4cfg.get_path()
|
print("ip4-config: %s" % ip4cfg.get_path())
|
||||||
main_loop.quit()
|
main_loop.quit()
|
||||||
|
|
||||||
def state_changed(obj, arg1, arg2, arg3):
|
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
|
# Device is connected
|
||||||
if arg1 == 100:
|
if arg1 == 100:
|
||||||
obj.connect('notify::ip4-config', do_notify)
|
obj.connect('notify::ip4-config', do_notify)
|
||||||
@@ -57,8 +57,8 @@ if __name__ == "__main__":
|
|||||||
dev = c.get_device_by_iface(dev_iface)
|
dev = c.get_device_by_iface(dev_iface)
|
||||||
if dev is None:
|
if dev is None:
|
||||||
sys.exit('Device \'%s\' not found' % dev_iface)
|
sys.exit('Device \'%s\' not found' % dev_iface)
|
||||||
print "Device: %s - %s" % (dev_iface, dev.get_device_type().value_name)
|
print("Device: %s - %s" % (dev_iface, dev.get_device_type().value_name))
|
||||||
print "---------------------------------------"
|
print("---------------------------------------")
|
||||||
|
|
||||||
dev.connect('state-changed', state_changed)
|
dev.connect('state-changed', state_changed)
|
||||||
main_loop = GLib.MainLoop()
|
main_loop = GLib.MainLoop()
|
||||||
|
@@ -29,8 +29,8 @@ if __name__ == "__main__":
|
|||||||
client = NM.Client.new(None)
|
client = NM.Client.new(None)
|
||||||
acons = client.get_active_connections()
|
acons = client.get_active_connections()
|
||||||
for ac in acons:
|
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:
|
if len(acons) == 0:
|
||||||
print "No active connections"
|
print("No active connections")
|
||||||
|
|
||||||
|
|
||||||
|
@@ -116,8 +116,8 @@ if __name__ == "__main__":
|
|||||||
dev = c.get_device_by_iface(dev_iface)
|
dev = c.get_device_by_iface(dev_iface)
|
||||||
if dev is None:
|
if dev is None:
|
||||||
sys.exit('Device \'%s\' not found' % dev_iface)
|
sys.exit('Device \'%s\' not found' % dev_iface)
|
||||||
print "Device: %s - %s" % (dev_iface, dev.get_device_type().value_name)
|
print("Device: %s - %s" % (dev_iface, dev.get_device_type().value_name))
|
||||||
print "---------------------------------------"
|
print("---------------------------------------")
|
||||||
|
|
||||||
print("IPv4 addresses:")
|
print("IPv4 addresses:")
|
||||||
print("---------------")
|
print("---------------")
|
||||||
@@ -134,7 +134,7 @@ if __name__ == "__main__":
|
|||||||
show_routes(dev, socket.AF_INET)
|
show_routes(dev, socket.AF_INET)
|
||||||
print
|
print
|
||||||
|
|
||||||
print "IPv6 addresses:"
|
print("IPv6 addresses:")
|
||||||
print("---------------")
|
print("---------------")
|
||||||
show_addresses(dev, socket.AF_INET6)
|
show_addresses(dev, socket.AF_INET6)
|
||||||
print
|
print
|
||||||
@@ -144,17 +144,17 @@ if __name__ == "__main__":
|
|||||||
show_gateway(dev, socket.AF_INET6)
|
show_gateway(dev, socket.AF_INET6)
|
||||||
print
|
print
|
||||||
|
|
||||||
print "IPv6 routes:"
|
print("IPv6 routes:")
|
||||||
print("------------")
|
print("------------")
|
||||||
show_routes(dev, socket.AF_INET6)
|
show_routes(dev, socket.AF_INET6)
|
||||||
print
|
print
|
||||||
|
|
||||||
print "IPv4 DNS:"
|
print("IPv4 DNS:")
|
||||||
print("------------")
|
print("------------")
|
||||||
show_dns(dev, socket.AF_INET)
|
show_dns(dev, socket.AF_INET)
|
||||||
print
|
print
|
||||||
|
|
||||||
print "IPv6 DNS:"
|
print("IPv6 DNS:")
|
||||||
print("------------")
|
print("------------")
|
||||||
show_dns(dev, socket.AF_INET6)
|
show_dns(dev, socket.AF_INET6)
|
||||||
print
|
print
|
||||||
|
@@ -27,7 +27,7 @@ from gi.repository import NM
|
|||||||
# This example asks settings service for all configured connections.
|
# This example asks settings service for all configured connections.
|
||||||
|
|
||||||
def print_values(setting, key, value, flags, data):
|
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__":
|
if __name__ == "__main__":
|
||||||
# create Client object
|
# create Client object
|
||||||
@@ -38,7 +38,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# print the connections' details
|
# print the connections' details
|
||||||
for c in connections:
|
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)
|
c.for_each_setting_value(print_values, None)
|
||||||
print "\n"
|
print("\n")
|
||||||
|
|
||||||
|
@@ -49,8 +49,8 @@ def print_device_info(device):
|
|||||||
if active_ap is not None:
|
if active_ap is not None:
|
||||||
ssid = ssid_to_utf8(active_ap)
|
ssid = ssid_to_utf8(active_ap)
|
||||||
info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid)
|
info = "Device: %s | Driver: %s | Active AP: %s" % (dev.get_iface(), dev.get_driver(), ssid)
|
||||||
print info
|
print(info)
|
||||||
print '=' * len(info)
|
print('=' * len(info))
|
||||||
|
|
||||||
def mode_to_string(mode):
|
def mode_to_string(mode):
|
||||||
if mode == getattr(NM, '80211Mode').INFRA:
|
if mode == getattr(NM, '80211Mode').INFRA:
|
||||||
@@ -114,16 +114,16 @@ def print_ap_info(ap):
|
|||||||
flags = ap.get_flags()
|
flags = ap.get_flags()
|
||||||
wpa_flags = ap.get_wpa_flags()
|
wpa_flags = ap.get_wpa_flags()
|
||||||
rsn_flags = ap.get_rsn_flags()
|
rsn_flags = ap.get_rsn_flags()
|
||||||
print "SSID: %s" % (ssid_to_utf8(ap))
|
print("SSID: %s" % (ssid_to_utf8(ap)))
|
||||||
print "BSSID: %s" % (ap.get_bssid())
|
print("BSSID: %s" % (ap.get_bssid()))
|
||||||
print "Frequency: %s" % (frequency)
|
print("Frequency: %s" % (frequency))
|
||||||
print "Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency))
|
print("Channel: %s" % (NM.utils_wifi_freq_to_channel(frequency)))
|
||||||
print "Mode: %s" % (mode_to_string(ap.get_mode()))
|
print("Mode: %s" % (mode_to_string(ap.get_mode())))
|
||||||
print "Flags: %s" % (flags_to_string(flags))
|
print("Flags: %s" % (flags_to_string(flags)))
|
||||||
print "WPA flags: %s" % (security_flags_to_string(wpa_flags))
|
print("WPA flags: %s" % (security_flags_to_string(wpa_flags)))
|
||||||
print "RSN flags: %s" % (security_flags_to_string(rsn_flags))
|
print("RSN flags: %s" % (security_flags_to_string(rsn_flags)))
|
||||||
print "Security: %s" % (flags_to_security(flags, wpa_flags, 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("Strength: %s %s%%" % (NM.utils_wifi_strength_bars(strength), strength))
|
||||||
print
|
print
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -35,12 +35,12 @@ import sys, socket
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# parse and validate arguments
|
# parse and validate arguments
|
||||||
if len(sys.argv) < 3:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
method = sys.argv[2]
|
method = sys.argv[2]
|
||||||
if (method == "static" or method == "manual") and len(sys.argv) < 5:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
uuid = sys.argv[1]
|
uuid = sys.argv[1]
|
||||||
@@ -81,7 +81,7 @@ if __name__ == "__main__":
|
|||||||
try:
|
try:
|
||||||
c.commit_changes(True, None)
|
c.commit_changes(True, None)
|
||||||
print("The connection profile has been updated.")
|
print("The connection profile has been updated.")
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
sys.stderr.write("Error: %s\n" % e)
|
sys.stderr.write("Error: %s\n" % e)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@@ -30,27 +30,27 @@ if args.do_set_nm_logging:
|
|||||||
dom_msg = ""
|
dom_msg = ""
|
||||||
if args.log_domains:
|
if args.log_domains:
|
||||||
dom_msg = " for domains: " + ','.join(args.log_domains)
|
dom_msg = " for domains: " + ','.join(args.log_domains)
|
||||||
print "Setting NetworkManager log level to '" + args.do_set_nm_logging + "'" + dom_msg
|
print("Setting NetworkManager log level to '" + args.do_set_nm_logging + "'" + dom_msg)
|
||||||
|
|
||||||
nm_bus = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
|
nm_bus = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
|
||||||
nm = dbus.Interface(nm_bus, dbus_interface='org.freedesktop.NetworkManager')
|
nm = dbus.Interface(nm_bus, dbus_interface='org.freedesktop.NetworkManager')
|
||||||
nm.SetLogging(args.do_set_nm_logging, ','.join(args.log_domains))
|
nm.SetLogging(args.do_set_nm_logging, ','.join(args.log_domains))
|
||||||
|
|
||||||
if args.do_set_mm_logging:
|
if args.do_set_mm_logging:
|
||||||
print "Setting ModemManager log level to '" + args.do_set_mm_logging + "'"
|
print("Setting ModemManager log level to '" + args.do_set_mm_logging + "'")
|
||||||
|
|
||||||
mm_bus = bus.get_object('org.freedesktop.ModemManager', '/org/freedesktop/ModemManager')
|
mm_bus = bus.get_object('org.freedesktop.ModemManager', '/org/freedesktop/ModemManager')
|
||||||
mm = dbus.Interface(mm_bus, dbus_interface='org.freedesktop.ModemManager')
|
mm = dbus.Interface(mm_bus, dbus_interface='org.freedesktop.ModemManager')
|
||||||
mm.SetLogging(args.do_set_mm_logging)
|
mm.SetLogging(args.do_set_mm_logging)
|
||||||
|
|
||||||
if args.do_set_wpa_logging:
|
if args.do_set_wpa_logging:
|
||||||
print "Setting wpa_supplicant log level to '" + args.do_set_wpa_logging + "'"
|
print("Setting wpa_supplicant log level to '" + args.do_set_wpa_logging + "'")
|
||||||
|
|
||||||
if 'debug' in args.do_set_wpa_logging or 'msgdump' in args.do_set_wpa_logging:
|
if 'debug' in args.do_set_wpa_logging or 'msgdump' in args.do_set_wpa_logging:
|
||||||
print "Enabling timestamps for wpasupplicant debugging logs"
|
print("Enabling timestamps for wpasupplicant debugging logs")
|
||||||
use_timestamps = dbus.Boolean(True, variant_level=1)
|
use_timestamps = dbus.Boolean(True, variant_level=1)
|
||||||
else:
|
else:
|
||||||
print "Disabling timestamps for wpasupplicant debugging logs"
|
print("Disabling timestamps for wpasupplicant debugging logs")
|
||||||
use_timestamps = dbus.Boolean(False, variant_level=1)
|
use_timestamps = dbus.Boolean(False, variant_level=1)
|
||||||
|
|
||||||
wpa_bus = bus.get_object('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1')
|
wpa_bus = bus.get_object('fi.w1.wpa_supplicant1', '/fi/w1/wpa_supplicant1')
|
||||||
|
Reference in New Issue
Block a user