2008-11-01 08:25:46 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
2008-11-01 08:25:46 +08:00
|
|
|
import sys
|
|
|
|
import dbus
|
|
|
|
import time
|
2010-06-13 19:22:18 +08:00
|
|
|
from optparse import OptionParser, make_option
|
2012-12-05 20:51:30 +08:00
|
|
|
import bluezutils
|
2008-11-01 08:25:46 +08:00
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
|
2010-06-13 19:22:18 +08:00
|
|
|
option_list = [
|
|
|
|
make_option("-i", "--device", action="store",
|
|
|
|
type="string", dest="dev_id"),
|
|
|
|
]
|
|
|
|
parser = OptionParser(option_list=option_list)
|
2008-11-01 08:25:46 +08:00
|
|
|
|
2010-06-13 19:22:18 +08:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2012-12-05 20:51:30 +08:00
|
|
|
adapter_path = bluezutils.find_adapter(options.dev_id).object_path
|
2010-06-13 19:22:18 +08:00
|
|
|
|
2010-08-31 22:20:30 +08:00
|
|
|
service = dbus.Interface(bus.get_object("org.bluez", adapter_path),
|
|
|
|
"org.bluez.Service")
|
2010-06-13 19:22:18 +08:00
|
|
|
|
|
|
|
if (len(args) < 1):
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Usage: %s <command>" % (sys.argv[0]))
|
|
|
|
print("")
|
|
|
|
print(" addrecord <file>")
|
2008-11-01 08:25:46 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
2010-06-13 19:22:18 +08:00
|
|
|
if (args[0] == "addrecord"):
|
|
|
|
if (len(args) < 2):
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Need file parameter")
|
2008-11-01 08:25:46 +08:00
|
|
|
else:
|
2010-06-13 19:22:18 +08:00
|
|
|
f = open(args[1])
|
2008-11-01 08:25:46 +08:00
|
|
|
record = f.read()
|
|
|
|
f.close()
|
2010-08-31 22:20:30 +08:00
|
|
|
handle = service.AddRecord(record)
|
2012-05-25 13:44:25 +08:00
|
|
|
print("0x%x" % (handle))
|
2008-11-01 08:25:46 +08:00
|
|
|
time.sleep(120)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2012-05-25 13:44:25 +08:00
|
|
|
print("Unknown command")
|
2008-11-01 08:25:46 +08:00
|
|
|
sys.exit(1)
|