test: Improve tethering scripts
[platform/upstream/connman.git] / test / disable-tethering
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 2):
7         print "Usage: %s type" % (sys.argv[0])
8
9 bus = dbus.SystemBus()
10
11 manager = dbus.Interface(bus.get_object('net.connman', "/"),
12                                         'net.connman.Manager')
13
14 def technology_disable_tethering(path, tech_type):
15         tech = dbus.Interface(bus.get_object("net.connman", path),
16                                                 "net.connman.Technology")
17
18         properties = tech.GetProperties()
19
20         for key in properties.keys():
21                 if key in ["Type"]:
22                         if properties[key] == tech_type:
23                                 print "Disabling %s tethering" % tech_type
24                                 tech.SetProperty("Tethering", dbus.Boolean(0))
25
26                                 return tech_type
27
28 properties = manager.GetProperties()
29
30 for key in properties.keys():
31         if key in ["Technologies"]:
32                 for path in properties[key]:
33                         tech = technology_disable_tethering(path, sys.argv[1])
34
35 if tech == None:
36         print "Failed to disable %s tethering" % (sys.argv[1])