How to use the mqttwarn.util.get_resource_content function in mqttwarn

To help you get started, we’ve selected a few mqttwarn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jpmens / mqttwarn / tests / test_util.py View on Github external
def test_get_resource_content():
    payload = get_resource_content('mqttwarn.examples', 'basic/mqttwarn.ini')
    assert '[defaults]' in payload
github jpmens / mqttwarn / mqttwarn / commands.py View on Github external
# Use generic commandline options schema and amend with current program name
    commandline_schema = run.__doc__.format(program=APP_NAME)

    # Read commandline options
    options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Python2/3 string encoding compat - sigh.
    # https://stackoverflow.com/questions/2737966/how-to-change-the-stdin-and-stdout-encoding-on-python-2/58449987#58449987
    utf8_writer = codecs.getwriter('utf-8')
    if sys.version_info.major <= 2:
        sys.stdout = utf8_writer(sys.stdout)
    else:
        sys.stdout = utf8_writer(sys.stdout.buffer)

    if options['make-config']:
        payload = get_resource_content('mqttwarn.examples', 'basic/mqttwarn.ini')
        print(payload)

    elif options['make-samplefuncs']:
        payload = get_resource_content('mqttwarn.examples', 'basic/samplefuncs.py')
        print(payload)

    elif options['--plugin'] and options['--data']:

        # Decode arguments
        plugin = options['--plugin']
        data = json.loads(options['--data'])

        # Launch service plugin in standalone mode
        launch_plugin_standalone(plugin, data)
github jpmens / mqttwarn / mqttwarn / commands.py View on Github external
options = docopt(commandline_schema, version=APP_NAME + ' ' + __version__)

    # Python2/3 string encoding compat - sigh.
    # https://stackoverflow.com/questions/2737966/how-to-change-the-stdin-and-stdout-encoding-on-python-2/58449987#58449987
    utf8_writer = codecs.getwriter('utf-8')
    if sys.version_info.major <= 2:
        sys.stdout = utf8_writer(sys.stdout)
    else:
        sys.stdout = utf8_writer(sys.stdout.buffer)

    if options['make-config']:
        payload = get_resource_content('mqttwarn.examples', 'basic/mqttwarn.ini')
        print(payload)

    elif options['make-samplefuncs']:
        payload = get_resource_content('mqttwarn.examples', 'basic/samplefuncs.py')
        print(payload)

    elif options['--plugin'] and options['--data']:

        # Decode arguments
        plugin = options['--plugin']
        data = json.loads(options['--data'])

        # Launch service plugin in standalone mode
        launch_plugin_standalone(plugin, data)


    # Run mqttwarn in service mode when no command line arguments are given
    else:
        run_mqttwarn()