Ejemplo n.º 1
0
def boot(options=None):

    options = options or {}
    options.setdefault('--debug', False)
    options.setdefault('--debug_mqtt', False)
    options.setdefault('--debug_mqtt_driver', False)
    options.setdefault('--debug_io', False)
    options.setdefault('--debug_influx', False)

    setup_logging()
    log.info(u'Starting ' + APP_NAME)

    # Read settings from configuration file
    configfile = get_configuration_file(options['--config'])
    log.info("Using configuration file {configfile}", configfile=configfile)
    settings = get_configuration(configfile)

    # Apply default settings
    apply_default_settings(settings)

    # Merge command line options into settings
    settings.setdefault('options', Bunch())
    for key, value in options.items():
        key = key.lstrip(u'--')
        key = key.replace(u'-', u'_')
        settings.options[key] = value

    # Setup the logging subsystem
    log_level = 'info'
    if settings.options.debug:
        log_level = 'debug'
    startLogging(settings,
                 stream=sys.stderr,
                 level=LogLevel.levelWithName(log_level))

    # Boot all enabled applications and vendors
    loader = KotoriBootloader(settings=settings)
    loader.boot_applications()
    loader.boot_vendors()

    # Boot web configuration GUI
    if 'config-web' in settings:
        boot_frontend(settings, debug=settings.options.debug)

    return loader
Ejemplo n.º 2
0
def run():

    setup_logging()
    log.info(u'Starting ' + APP_NAME)

    # Read commandline options
    # TODO: Do it the Twisted way
    options = docopt(__doc__, version=APP_NAME)

    # Read settings from configuration file
    configfile = get_configuration_file(options['--config'])
    log.info("Using configuration file {configfile}", configfile=configfile)
    settings = get_configuration(configfile)

    # Apply default settings
    apply_default_settings(settings)

    # Merge command line options into settings
    settings.setdefault('options', Bunch())
    for key, value in options.iteritems():
        key = key.lstrip(u'--')
        key = key.replace(u'-', u'_')
        settings.options[key] = value

    # Setup the logging subsystem
    log_level = 'info'
    if settings.options.debug:
        log_level = 'debug'
    startLogging(settings,
                 stream=sys.stderr,
                 level=LogLevel.levelWithName(log_level))

    # Boot all enabled applications and vendors
    loader = KotoriBootloader(settings=settings)
    loader.boot_applications()
    loader.boot_vendors()

    # Boot web configuration GUI
    if 'config-web' in settings:
        boot_frontend(settings, debug=settings.options.debug)

    # Enter Twisted reactor loop
    reactor.run()
Ejemplo n.º 3
0
def run():

    setup_logging()
    log.info(u'Starting ' + APP_NAME)

    # Read commandline options
    # TODO: Do it the Twisted way
    options = docopt(__doc__, version=APP_NAME)

    # Read settings from configuration file
    configfile = get_configuration_file(options['--config'])
    log.info("Using configuration file {configfile}", configfile=configfile)
    settings = get_configuration(configfile)

    # Apply default settings
    apply_default_settings(settings)

    # Merge command line options into settings
    settings.setdefault('options', Bunch())
    for key, value in options.iteritems():
        key = key.lstrip(u'--')
        key = key.replace(u'-', u'_')
        settings.options[key] = value

    # Setup the logging subsystem
    log_level = 'info'
    if settings.options.debug:
        log_level = 'debug'
    startLogging(settings, stream=sys.stderr, level=LogLevel.levelWithName(log_level))

    # Boot all enabled applications and vendors
    loader = KotoriBootloader(settings=settings)
    loader.boot_applications()
    loader.boot_vendors()

    # Boot web configuration GUI
    if 'config-web' in settings:
        boot_frontend(settings, debug=settings.options.debug)

    # Enter Twisted reactor loop
    reactor.run()
Ejemplo n.º 4
0
def message():
    """
    Usage:
      lst-message list-channels                    [--config etc/kotori.ini] [--debug]
      lst-message <channel>  decode     <payload>  [--config etc/kotori.ini] [--debug]
      lst-message <channel>  transform  <payload>  [--config etc/kotori.ini] [--debug]
      lst-message <channel>  send       <payload>  --target=udp://localhost:8888 [--config etc/kotori.ini]
      lst-message <channel>  info       [<name>]   [--config etc/kotori.ini] [--debug]
      lst-message --version
      lst-message (-h | --help)

    Options:
      --config etc/kotori.ini   Use specified configuration file, otherwise try KOTORI_CONFIG environment variable
      --version                 Show version information
      --debug                   Enable debug messages
      -h --help                 Show this screen

    Examples:

      # Initialize environment with path to configuration file, either on development or production
      export KOTORI_CONFIG=`pwd`/etc/development.ini
      export KOTORI_CONFIG=/etc/kotori/kotori.ini

      # Show list of channels
      lst-message list-channels

      # Display list of structs for channel "h2m"
      lst-message h2m info

      # Display details about struct "struct_fuelcell_r" in channel "h2m"
      lst-message h2m info struct_fuelcell_r

      # Decode message for channel "h2m"
      lst-message h2m decode 0x05022a0021

      # Send message to channel "h2m"
      lst-message h2m send 0x05022a0021 --target=udp://localhost:8888

    """

    # parse command line arguments
    options = docopt(message.__doc__, version=APP_NAME)
    #print 'options: {}'.format(options)

    debug = options.get('--debug')

    # setup logging
    log_level = logging.INFO
    if debug:
        log_level = logging.DEBUG
    setup_logging(log_level)

    # load configuration
    config_file = get_configuration_file(options.get('--config'))
    config = get_configuration(config_file)

    # first command
    if options.get('list-channels'):
        lst_channels(config)
        sys.exit()

    # activate/mount application representing selected channel
    channel_label = options.get('<channel>')
    channel_name  = sanitize_channel_label(channel_label)
    if channel_name == channel_label:
        channel_label = compute_channel_label(channel_name)
    channel = Bunch(
        name  = channel_name,
        label = channel_label)
    # TODO: overhaul _active_ mechanics
    try:
        config['_active_'] = config[channel.label]
        channel.settings = config['_active_']
    except KeyError:
        logger.error('Channel configuration object "{channel_label}" not found'.format(channel_label = channel.label))
        raise

    # initialize library, setup BinaryMessageAdapter
    adapter = setup_binary_message_adapter(config)

    # dispatch to generic message decoding
    lst_message(channel, adapter, options)