Ejemplo n.º 1
0
async def main():
    parser = argparse.ArgumentParser(description="Expose the OH DB as a filesystem.")
    add_common_args(parser)
    parser.add_argument("--mountpoint", '-m', type=str, metavar="DIR",
                        help="Where to mount the filesystem.")
    args = parser.parse_args()

    enable_logging(args.log_target, args.log_level)

    tree = await Tree.connect((args.home_address, args.home_port),
                          args.ca_chain, args.certificate, args.private_key)
    th = Thread(target=lambda mp, t, l: FileSystem(mp, t, l).run(True),
                args=(args.mountpoint, tree, asyncio.get_event_loop()))
    th.start()
Ejemplo n.º 2
0
def main():
    desc = 'A REST gateway for interacting with OpenHouse over HTTP.'
    parser = argparse.ArgumentParser(description=desc)
    add_common_args(parser)
    group = parser.add_argument_group("REST specific args")
    group.add_argument('-a', '--address', default='0.0.0.0',
                       help="The address to listen for REST on.")
    group.add_argument('-p', '--port', default=8080, type=int,
                       help="The port to listen for REST on.")
    args = parser.parse_args()

    enable_logging(args.log_target, args.log_level)

    tree = asyncio.get_event_loop().run_until_complete(make_connection(args))

    app = web.Application()
    get_handler, post_handler = make_handler(tree)
    paths = app.router.add_resource(r'/{path:[^{}]+}')
    paths.add_route('GET', get_handler)
    paths.add_route('POST', post_handler)
    log.info("Listening on '{}:{}'".format(args.address, args.port))
    web.run_app(app, host=args.address, port=args.port)