-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsd_browser.py
More file actions
executable file
·36 lines (27 loc) · 1.1 KB
/
sd_browser.py
File metadata and controls
executable file
·36 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
"""Example how to query an Arrowhead Service Directory"""
import logging
import argparse
import sys
import asyncio
# for pretty-printing the results
from pprint import pprint
def print_results(browser):
pprint(browser.services, indent=4, width=160)
loglevels = [logging.CRITICAL, logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
from soa import ServiceDirectoryBrowser
@asyncio.coroutine
def main(argv=None):
"""Program main entry point"""
parser = argparse.ArgumentParser(argv)
parser.add_argument("-v", "--verbosity", type=int, default=4,
help="set logging verbosity, 1=CRITICAL, 5=DEBUG")
parser.add_argument('url', nargs='?', default='coap://[::1]/servicediscovery/service',
help="URL to service directory")
args = parser.parse_args()
# logging setup
logging.basicConfig(level=loglevels[args.verbosity-1])
sdb = ServiceDirectoryBrowser(uri=args.url, notify=print_results)
yield from sdb.start_observe()
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main(sys.argv))