blob: b44b91df165177192cca276ec1d66a76960e8c59 [file] [log] [blame]
#!/usr/bin/python
import sys
import dbus
import re
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()),
"org.bluez.Adapter")
if (len(sys.argv) < 2):
print "Usage: %s <command>" % (sys.argv[0])
print ""
print " list"
print " create <address>"
print " remove <address|path>"
print " discover <address> [pattern]"
print " class <address>"
print " name <address>"
print " alias <address> [alias]"
print " trusted <address> [yes/no]"
print " blocked <address> [yes/no]"
sys.exit(1)
if (sys.argv[1] == "list"):
list = adapter.ListDevices()
print list
sys.exit(0)
if (sys.argv[1] == "create"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
device = adapter.CreateDevice(sys.argv[2])
print device
sys.exit(0)
if (sys.argv[1] == "remove"):
if (len(sys.argv) < 3):
print "Need address or object path parameter"
else:
try:
path = adapter.FindDevice(sys.argv[2])
except:
path = sys.argv[2]
adapter.RemoveDevice(path)
sys.exit(0)
if (sys.argv[1] == "discover"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
if (len(sys.argv) < 4):
pattern = ""
else:
pattern = sys.argv[3]
services = device.DiscoverServices(pattern);
for key in services.keys():
p = re.compile(">.*?<")
xml = p.sub("><", services[key].replace("\n", ""))
print "[ 0x%5x ]" % (key)
print xml
print
sys.exit(0)
if (sys.argv[1] == "class"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
properties = device.GetProperties()
print "0x%06x" % (properties["Class"])
sys.exit(0)
if (sys.argv[1] == "name"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
properties = device.GetProperties()
print properties["Name"]
sys.exit(0)
if (sys.argv[1] == "alias"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
if (len(sys.argv) < 4):
properties = device.GetProperties()
print properties["Alias"]
else:
device.SetProperty("Alias", sys.argv[3])
sys.exit(0)
if (sys.argv[1] == "trusted"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
if (len(sys.argv) < 4):
properties = device.GetProperties()
print properties["Trusted"]
else:
if (sys.argv[3] == "yes"):
value = dbus.Boolean(1)
elif (sys.argv[3] == "no"):
value = dbus.Boolean(0)
else:
value = dbus.Boolean(sys.argv[3])
device.SetProperty("Trusted", value)
sys.exit(0)
if (sys.argv[1] == "blocked"):
if (len(sys.argv) < 3):
print "Need address parameter"
else:
path = adapter.FindDevice(sys.argv[2])
device = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Device")
if (len(sys.argv) < 4):
properties = device.GetProperties()
print properties["Blocked"]
else:
if (sys.argv[3] == "yes"):
value = dbus.Boolean(1)
elif (sys.argv[3] == "no"):
value = dbus.Boolean(0)
else:
value = dbus.Boolean(sys.argv[3])
device.SetProperty("Blocked", value)
sys.exit(0)
print "Unknown command"
sys.exit(1)