From 22279e047bbe031d9b8fa14a53f294626c297a21 Mon Sep 17 00:00:00 2001 From: Hendrik Buschmeier <hbuschme@uni-bielefeld.de> Date: Thu, 7 Jan 2016 16:08:21 +0100 Subject: [PATCH] ipaaca-python: Added --rsb-spread-host/port to IpaacaArgumentParser. --- ipaacalib/python/src/ipaaca/__init__.py | 24 +++++++++++++++++---- ipaacalib/python/src/ipaaca/defaults.py | 7 ++++++- ipaacalib/python/src/ipaaca/misc.py | 28 ++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/ipaacalib/python/src/ipaaca/__init__.py b/ipaacalib/python/src/ipaaca/__init__.py index 998fe65..9314caf 100755 --- a/ipaacalib/python/src/ipaaca/__init__.py +++ b/ipaacalib/python/src/ipaaca/__init__.py @@ -4,7 +4,7 @@ # "Incremental Processing Architecture # for Artificial Conversational Agents". # -# Copyright (c) 2009-2014 Social Cognitive Systems Group +# Copyright (c) 2009-2016 Social Cognitive Systems Group # CITEC, Bielefeld University # # http://opensource.cit-ec.de/projects/ipaaca/ @@ -32,6 +32,7 @@ from __future__ import division, print_function +import os import threading import rsb @@ -51,7 +52,13 @@ __RSB_INITIALIZED = False def initialize_ipaaca_rsb_if_needed(): - '''Register own RSB Converters and initialise RSB from default config file.''' + """Initialise rsb if not yet initialise. + + * Register own RSB onverters. + * Initialise RSB from enviroment variables, rsb config file, or + from default values for RSB spread host and port (via + ipaaca.defaults or ipaaca.misc.IpaacaArgumentParser). + """ global __RSB_INITIALIZED with __RSB_INITIALIZER_LOCK: if __RSB_INITIALIZED: @@ -93,7 +100,16 @@ def initialize_ipaaca_rsb_if_needed(): rsb.converter.registerGlobalConverter( rsb.converter.ProtocolBufferConverter( messageClass=ipaaca_pb2.IURetraction)) - - rsb.__defaultParticipantConfig = rsb.ParticipantConfig.fromDefaultSources() + + if ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREAD_HOST is not None: + os.environ['RSB_TRANSPORT_SPREAD_HOST'] = str( + ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREAD_HOST) + + if ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREAD_PORT is not None: + os.environ['RSB_TRANSPORT_SPREAD_PORT'] = str( + ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREAD_PORT) + + rsb.__defaultParticipantConfig = \ + rsb.ParticipantConfig.fromDefaultSources() __RSB_INITIALIZED = True diff --git a/ipaacalib/python/src/ipaaca/defaults.py b/ipaacalib/python/src/ipaaca/defaults.py index 706c714..bf3d0f0 100644 --- a/ipaacalib/python/src/ipaaca/defaults.py +++ b/ipaacalib/python/src/ipaaca/defaults.py @@ -4,7 +4,7 @@ # "Incremental Processing Architecture # for Artificial Conversational Agents". # -# Copyright (c) 2009-2014 Social Cognitive Systems Group +# Copyright (c) 2009-2016 Social Cognitive Systems Group # CITEC, Bielefeld University # # http://opensource.cit-ec.de/projects/ipaaca/ @@ -33,6 +33,11 @@ IPAACA_DEFAULT_CHANNEL = 'default' IPAACA_LOGGER_NAME = 'ipaaca' + IPAACA_DEFAULT_LOGGING_LEVEL = 'WARNING' IPAACA_DEFAULT_IU_PAYLOAD_TYPE = 'JSON' # one of ipaaca.iu.IUPayloadType + +IPAACA_DEFAULT_RSB_SPREAD_HOST = None + +IPAACA_DEFAULT_RSB_SPREAD_PORT = None diff --git a/ipaacalib/python/src/ipaaca/misc.py b/ipaacalib/python/src/ipaaca/misc.py index 44932d5..b3bec91 100644 --- a/ipaacalib/python/src/ipaaca/misc.py +++ b/ipaacalib/python/src/ipaaca/misc.py @@ -4,7 +4,7 @@ # "Incremental Processing Architecture # for Artificial Conversational Agents". # -# Copyright (c) 2009-2014 Social Cognitive Systems Group +# Copyright (c) 2009-2016 Social Cognitive Systems Group # CITEC, Bielefeld University # # http://opensource.cit-ec.de/projects/ipaaca/ @@ -124,6 +124,16 @@ class IpaacaArgumentParser(argparse.ArgumentParser): rsb_logger.removeHandler(__GENERIC_NO_LOG_HANDLER) rsb_logger.setLevel(level=values) + class IpaacaRSBSpreadHost(argparse.Action): + + def __call__(self, parser, namespace, values, option_string=None): + ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREAD_HOST = values + + class IpaacaRSBSpreadPort(argparse.Action): + + def __call__(self, parser, namespace, values, option_string=None): + ipaaca.defaults.IPAACA_DEFAULT_RSB_SPREADPORT = values + def __init__(self, prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=argparse.HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, @@ -136,6 +146,7 @@ class IpaacaArgumentParser(argparse.ArgumentParser): conflict_handler=conflict_handler, add_help=add_help) def _add_ipaaca_lib_arguments(self): + # CMD-arguments for ipaaca ipaacalib_group = self.add_argument_group('IPAACA library arguments') ipaacalib_group.add_argument( '--ipaaca-payload-type', @@ -157,6 +168,7 @@ class IpaacaArgumentParser(argparse.ArgumentParser): choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'], dest='_ipaaca_logging_level_', help="enable IPAACA logging with threshold") + # CMD-arguments for rsb rsblib_group = self.add_argument_group('RSB library arguments') rsblib_group.add_argument( '--rsb-enable-logging', @@ -164,6 +176,20 @@ class IpaacaArgumentParser(argparse.ArgumentParser): choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'], dest='_ipaaca_rsb_enable_logging_', help="enable RSB logging with threshold") + rsblib_group.add_argument( + '--rsb-spread-host', + action=self.IpaacaRSBSpreadHost, + default=None, + dest='_ipaaca_rsb_set_spread_host_', + metavar='HOST', + help="set RSB spread host") + rsblib_group.add_argument( + '--rsb-spread-port', + action=self.IpaacaRSBSpreadPort, + default=None, + dest='_ipaaca_rsb_set_spread_port_', + metavar='PORT', + help="set RSB spread port") def parse_args(self, args=None, namespace=None): self._add_ipaaca_lib_arguments() # Add ipaaca-args just before parsing -- GitLab