Add parsing of Domainname, Hostname and Timeserver results
[framework/connectivity/connman.git] / test / test-profile
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 bus = dbus.SystemBus()
7
8 manager = dbus.Interface(bus.get_object("org.moblin.connman", "/"),
9                                         "org.moblin.connman.Manager")
10
11 if len(sys.argv) < 2:
12         print "Usage: %s <command>" % (sys.argv[0])
13         print ""
14         print "  list"
15         print "  name <profile> [name]"
16         print ""
17         print "  create <profile> [name]"
18         print "  remove <profile>"
19         sys.exit(1)
20
21 def print_profiles(profiles, active):
22         for path in profiles:
23                 profile = dbus.Interface(bus.get_object("org.moblin.connman", path),
24                                                 "org.moblin.connman.Profile")
25
26                 properties = profile.GetProperties()
27
28                 identifier = path[path.rfind("/") + 1:]
29
30                 if (path == active):
31                         default = "*"
32                 else:
33                         default = " "
34
35                 if "Name" in properties.keys():
36                         name = properties["Name"]
37                 else:
38                         name = "<unnamed>"
39
40                 print "%s %-12s %s" % (default, identifier, name)
41
42 if sys.argv[1] in ["list", "show"]:
43         properties = manager.GetProperties()
44
45         print_profiles(properties["Profiles"], properties["ActiveProfile"])
46
47 elif sys.argv[1] in ["name"]:
48         if (len(sys.argv) < 3):
49                 print "Need at least profile parameter"
50                 sys.exit(1)
51
52         path = "/profile/" + sys.argv[2]
53
54         profile = dbus.Interface(bus.get_object("org.moblin.connman", path),
55                                                 "org.moblin.connman.Profile")
56
57         if (len(sys.argv) > 3):
58                 name = sys.argv[3]
59
60                 profile.SetProperty("Name", name);
61
62                 print "Name \"%s\" set for %s" % (name, sys.argv[2])
63         else:
64                 properties = profile.GetProperties()
65
66                 if "Name" in properties.keys():
67                         name = "\"" + properties["Name"] + "\""
68                 else:
69                         name = "<unnamed>"
70
71                 print "Name for %s is %s" % (sys.argv[2], name)
72
73 elif sys.argv[1] in ["create", "add"]:
74         if (len(sys.argv) < 3):
75                 print "Profile parameter required"
76                 sys.exit(1)
77
78         path = manager.CreateProfile(sys.argv[2])
79
80         print "New profile created at %s" % (path)
81
82         profile = dbus.Interface(bus.get_object("org.moblin.connman", path),
83                                                 "org.moblin.connman.Profile")
84
85         if (len(sys.argv) > 3):
86                 name = sys.argv[3]
87
88                 profile.SetProperty("Name", name);
89
90                 print "Name \"%s\" set for %s" % (name, sys.argv[2])
91
92 elif sys.argv[1] in ["remove", "delete", "del"]:
93         if (len(sys.argv) < 3):
94                 print "Profile parameter required"
95                 sys.exit(1)
96
97         path = "/profile/" + sys.argv[2]
98
99         manager.RemoveProfile(path)
100
101 else:
102         print "Unknown command"