Example #1
0
async def main(*args, **kwargs):
    arguments = docopt(__doc__, version=get_version())
    #print(arguments)
    formatter = "[%(asctime)s] :: %(levelname)s - %(message)s"

    if arguments['-d']:
        level = logging.DEBUG
    else:
        level = logging.INFO
    logging.basicConfig(level=level, format=formatter)

    config = None
    if arguments['-c']:
        config = read_yaml_config(arguments['-c'])
    else:
        config = read_yaml_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default_client.yaml'))
        logger.debug("Using default configuration")

    client_id = arguments.get("-i", None)
    if not client_id:
        client_id = _gen_client_id()

    if arguments['-k']:
        config['keep_alive'] = int(arguments['-k'])

    if arguments['--will-topic'] and arguments['--will-message'] and arguments['--will-qos']:
        config['will'] = dict()
        config['will']['topic'] = arguments['--will-topic']
        config['will']['message'] = arguments['--will-message'].encode('utf-8')
        config['will']['qos'] = int(arguments['--will-qos'])
        config['will']['retain'] = arguments['--will-retain']

    async with open_mqttclient(client_id=client_id, config=config) as C:
        await do_pub(C, arguments)
Example #2
0
async def main(config, debug):
    formatter = "[%(asctime)s] :: %(levelname)s - %(message)s"

    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level, format=formatter)

    if not config:
        config = os.path.join(os.path.dirname(os.path.realpath(__file__)), "default_broker.yaml")
        logger.debug("Using default configuration")
    config = read_yaml_config(config)

    try:
        from distkv.util import as_service
    except ImportError:
        as_service = None

    async with AsyncExitStack() as stack:
        await stack.enter_async_context(main_scope())
        await stack.enter_async_context(create_broker(config))
        try:
            from distkv.util import as_service
        except ImportError:
            pass
        else:
            evt = await stack.enter_async_context(as_service())
            await evt.set()
        while True:
            await anyio.sleep(99999)
Example #3
0
async def main():
    arguments = docopt(__doc__, version=get_version())
    # print(arguments)
    formatter = "[%(asctime)s] :: %(levelname)s - %(message)s"

    if arguments["-d"]:
        level = logging.DEBUG
    else:
        level = logging.INFO
    logging.basicConfig(level=level, format=formatter)

    config = None
    if arguments["-c"]:
        config = read_yaml_config(arguments["-c"])
    else:
        config = read_yaml_config(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "default_client.yaml"))
        logger.debug(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         "default_client.yaml"))
        logger.debug("Using default configuration")

    client_id = arguments.get("-i", None)
    if not client_id:
        client_id = _gen_client_id()

    if arguments["-k"]:
        config["keep_alive"] = int(arguments["-k"])

    if arguments["--will-topic"] and arguments["--will-message"]:
        config["will"] = dict()
        config["will"]["topic"] = arguments["--will-topic"]
        config["will"]["message"] = arguments["--will-message"].encode("utf-8")
        config["will"]["qos"] = _get_qos(arguments)
        config["will"]["retain"] = arguments["--will-retain"]

    async with open_mqttclient(client_id=client_id,
                               config=config,
                               codec=arguments["-C"]) as C:
        await do_sub(C, arguments)
Example #4
0
async def main(config, debug):
    formatter = "[%(asctime)s] :: %(levelname)s - %(message)s"

    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level, format=formatter)

    if not config:
        config = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'default_broker.yaml')
        logger.debug("Using default configuration")
    config = read_yaml_config(config)

    async with create_broker(config) as broker:
        while True:
            await anyio.sleep(99999)