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:
Yifan J
2017-12-02 12:44:50 +08:00
committed by Thomas Haller
parent 5e239d2c04
commit 797d9c4403
25 changed files with 104 additions and 104 deletions

View File

@@ -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, e:
except Exception as e:
sys.stderr.write("Error: %s\n" % e)
main_loop.quit()

View File

@@ -78,6 +78,6 @@ if __name__ == "__main__":
try:
client.deactivate_connection(ac, None)
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)

View File

@@ -35,14 +35,14 @@ from gi.repository import GLib, NM
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()

View File

@@ -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")

View File

@@ -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

View File

@@ -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")

View File

@@ -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__":

View File

@@ -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, e:
except Exception as e:
sys.stderr.write("Error: %s\n" % e)
break