smsutil: Fix warning
[platform/upstream/ofono.git] / test / set-context-property
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if len(sys.argv) < 4:
7         print "Usage: set-context-property <context> <name> <value>"
8         sys.exit(1)
9
10 bus = dbus.SystemBus()
11
12 manager = dbus.Interface(bus.get_object('org.ofono', '/'),
13                                                 'org.ofono.Manager')
14
15 modems = manager.GetModems()
16
17 for path, properties in modems:
18         if "org.ofono.ConnectionManager" not in properties["Interfaces"]:
19                 continue
20
21         connman = dbus.Interface(bus.get_object('org.ofono', path),
22                                         'org.ofono.ConnectionManager')
23
24         contexts = connman.GetContexts()
25
26         if (len(contexts) == 0):
27                 print "No context available"
28                 sys.exit(1)
29
30         path = contexts[int(sys.argv[1])][0]
31         context = dbus.Interface(bus.get_object('org.ofono', path),
32                                         'org.ofono.ConnectionContext')
33
34         try:
35                 context.SetProperty(sys.argv[2], sys.argv[3])
36         except dbus.DBusException, e:
37                 print "Error setting context %s property %s: %s" %\
38                                 (path, sys.argv[2], str(e))
39                 exit(2)