Home | History | Annotate | Download | only in test
      1 #!/usr/bin/python
      2 
      3 import sys
      4 import dbus
      5 import time
      6 from optparse import OptionParser, make_option
      7 
      8 bus = dbus.SystemBus()
      9 
     10 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
     11 
     12 option_list = [
     13 		make_option("-i", "--device", action="store",
     14 				type="string", dest="dev_id"),
     15 		]
     16 parser = OptionParser(option_list=option_list)
     17 
     18 (options, args) = parser.parse_args()
     19 
     20 if options.dev_id:
     21 	adapter_path = manager.FindAdapter(options.dev_id)
     22 else:
     23 	adapter_path = manager.DefaultAdapter()
     24 
     25 service = dbus.Interface(bus.get_object("org.bluez", adapter_path),
     26 						"org.bluez.Service")
     27 
     28 if (len(args) < 1):
     29 	print "Usage: %s <command>" % (sys.argv[0])
     30 	print ""
     31 	print "  addrecord <file>"
     32 	sys.exit(1)
     33 
     34 if (args[0] == "addrecord"):
     35 	if (len(args) < 2):
     36 		print "Need file parameter"
     37 	else:
     38 		f = open(args[1])
     39 		record = f.read()
     40 		f.close()
     41 		handle = service.AddRecord(record)
     42 		print "0x%x" % (handle)
     43 		time.sleep(120)
     44 	sys.exit(0)
     45 
     46 print "Unknown command"
     47 sys.exit(1)
     48