def run(): """ Usage: {program} [make-config] {program} [make-samplefuncs] {program} [--plugin=] [--data=] {program} --version {program} (-h | --help) Configuration file options: make-config Will dump configuration file content to STDOUT, suitable for redirecting into a configuration file. Miscellaneous options: --version Show version information -h --help Show this screen """ # 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) # Run mqttwarn in service mode when no command line arguments are given else: run_mqttwarn()
def test_get_resource_content(): payload = get_resource_content('mqttwarn.examples', 'basic/mqttwarn.ini') assert '[defaults]' in payload
def test_get_resource_content(): payload = get_resource_content("mqttwarn.examples", "basic/mqttwarn.ini") assert "[defaults]" in payload
def run(): """ Usage: {program} [make-config] {program} [make-samplefuncs] {program} [--config=] [--config-file=] [--plugin=] [--options=] {program} --version {program} (-h | --help) No options: mqttwarn will start as a service. Interactive options: [--config=] Use configuration settings from JSON string [--config-file=] Use configuration settings from JSON file [--plugin=] The plugin name to load. This can either be a full qualified Python package/module name or a path to a Python file. [--options=] Configuration options to propagate to the plugin entrypoint. Bootstrapping options: make-config Dump configuration file blueprint to STDOUT, suitable for redirecting into a configuration file. make-samplefuncs Dump blueprint for custom functions file to STDOUT, suitable for redirecting into a `samplefuncs.py` file. Miscellaneous options: --version Show version information -h --help Show this screen """ # 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['--options']: # Decode arguments arg_plugin = options['--plugin'] arg_options = json.loads(options['--options']) arg_config = None if "--config" in options and options['--config'] is not None: arg_config = json.loads(options['--config']) # Launch service plugin in standalone mode launch_plugin_standalone(arg_plugin, arg_options, configfile=options.get("--config-file"), config_more=arg_config) # Run mqttwarn in service mode when no command line arguments are given else: run_mqttwarn()