• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3import sys
4import dbus
5import time
6from optparse import OptionParser, make_option
7
8bus = dbus.SystemBus()
9
10manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
11
12option_list = [
13		make_option("-i", "--device", action="store",
14				type="string", dest="dev_id"),
15		]
16parser = OptionParser(option_list=option_list)
17
18(options, args) = parser.parse_args()
19
20if options.dev_id:
21	adapter_path = manager.FindAdapter(options.dev_id)
22else:
23	adapter_path = manager.DefaultAdapter()
24
25adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
26							"org.bluez.Adapter")
27
28if (len(args) < 1):
29	print "Usage: %s <command>" % (sys.argv[0])
30	print ""
31	print "  address"
32	print "  name [name]"
33	print "  powered [on/off]"
34	print "  pairable [on/off]"
35	print "  pairabletimeout [timeout]"
36	print "  discoverable [on/off]"
37	print "  discoverabletimeout [timeout]"
38	print "  discovering"
39	sys.exit(1)
40
41if (args[0] == "address"):
42	properties = adapter.GetProperties()
43	print properties["Address"]
44	sys.exit(0)
45
46if (args[0] == "name"):
47	if (len(args) < 2):
48		properties = adapter.GetProperties()
49		print properties["Name"]
50	else:
51		adapter.SetProperty("Name", args[1])
52	sys.exit(0)
53
54if (args[0] == "powered"):
55	if (len(args) < 2):
56		properties = adapter.GetProperties()
57		print properties["Powered"]
58	else:
59		if (args[1] == "on"):
60			value = dbus.Boolean(1)
61		elif (args[1] == "off"):
62			value = dbus.Boolean(0)
63		else:
64			value = dbus.Boolean(args[1])
65		adapter.SetProperty("Powered", value)
66	sys.exit(0)
67
68if (args[0] == "pairable"):
69	if (len(args) < 2):
70		properties = adapter.GetProperties()
71		print properties["Pairable"]
72	else:
73		if (args[1] == "on"):
74			value = dbus.Boolean(1)
75		elif (args[1] == "off"):
76			value = dbus.Boolean(0)
77		else:
78			value = dbus.Boolean(args[1])
79		adapter.SetProperty("Pairable", value)
80	sys.exit(0)
81
82if (args[0] == "pairabletimeout"):
83	if (len(args) < 2):
84		properties = adapter.GetProperties()
85		print properties["PairableTimeout"]
86	else:
87		timeout = dbus.UInt32(args[1])
88		adapter.SetProperty("PairableTimeout", timeout)
89	sys.exit(0)
90
91if (args[0] == "discoverable"):
92	if (len(args) < 2):
93		properties = adapter.GetProperties()
94		print properties["Discoverable"]
95	else:
96		if (args[1] == "on"):
97			value = dbus.Boolean(1)
98		elif (args[1] == "off"):
99			value = dbus.Boolean(0)
100		else:
101			value = dbus.Boolean(args[1])
102		adapter.SetProperty("Discoverable", value)
103	sys.exit(0)
104
105if (args[0] == "discoverabletimeout"):
106	if (len(args) < 2):
107		properties = adapter.GetProperties()
108		print properties["DiscoverableTimeout"]
109	else:
110		timeout = dbus.UInt32(args[1])
111		adapter.SetProperty("DiscoverableTimeout", timeout)
112	sys.exit(0)
113
114if (args[0] == "discovering"):
115	properties = adapter.GetProperties()
116	print properties["Discovering"]
117	sys.exit(0)
118
119print "Unknown command"
120sys.exit(1)
121