def __init__(self, default_transporter="RabbitMQHapiConnector"): # This level is used until __parse_argument() is called. # TODO: Shoud be configurable. For example, by environment variable logging.basicConfig(level="INFO") self.__error_sleep_time = self.DEFAULT_ERROR_SLEEP_TIME parser = argparse.ArgumentParser() choices = ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL") parser.add_argument("--log", dest="loglevel", choices=choices, default="INFO") parser.add_argument("-p", "--disable-poller", action="store_true") help_msg = """ Minimum status logging interval in seconds. The actual interval depends on the implementation and is typically larger than this parameter. """ parser.add_argument("--status-log-interval", type=int, default=600, help=help_msg) self.__transporter_manager = transporter.Manager(default_transporter) self.__transporter_manager.define_arguments(parser) self.__parser = parser self.__main_plugin = None self.__poller = None
def __init__(self, default_transporter="RabbitMQHapiConnector"): parser = argparse.ArgumentParser() hap.initialize_logger(parser) parser.add_argument("-p", "--disable-poller", action="store_true") parser.add_argument("--polling-targets", nargs="*", choices=haplib.BasePoller.ACTIONS, default=haplib.BasePoller.ACTIONS, help="Names of polloing action. Defaut is all.") help_msg = """ Minimum status logging interval in seconds. The actual interval depends on the implementation and is typically larger than this parameter. """ parser.add_argument("--status-log-interval", type=int, default=600, help=help_msg) self.__transporter_manager = transporter.Manager(default_transporter) self.__transporter_manager.define_arguments(parser) self.__parser = parser self.__main_plugin = None self.__poller = None
def basic_setup(arg_def_func=None, prog_name="Simple Server for HAPI2"): parser = argparse.ArgumentParser() transporter_manager = transporter.Manager(DEFAULT_TRANSPORTER) transporter_manager.define_arguments(parser) if arg_def_func is not None: arg_def_func(parser) args = parser.parse_args() if args.log_conf is not None: logging.config.fileConfig(args.log_conf) else: logger.addHandler(logging.StreamHandler(stream=sys.stdout)) logger.setLevel(logging.INFO) logger.info(prog_name) transporter_class = transporter_manager.find(args.transporter) if transporter_class is None: logger.critical("Not found transporter: %s" % args.transporter) raise SystemExit() transporter_args = {"class": transporter_class} transporter_args.update(transporter_class.parse_arguments(args)) transporter_args["amqp_send_queue_suffix"] = "-T" transporter_args["amqp_recv_queue_suffix"] = "-S" return args, transporter_args
def test_register_and_find(self): class testTrans: @classmethod def define_arguments(cls, parser): pass manager = transporter.Manager(None) self.assertIsNone(manager.find("testTrans")) transporter.Manager.register(testTrans) self.assertEquals(manager.find("testTrans"), testTrans)
def __init__(self, default_transporter="RabbitMQHapiConnector"): parser = argparse.ArgumentParser(add_help=False) group = parser.add_argument_group("Config") help_msg = """ A configuration file. Other command line arguments override items in the config. file. """ group.add_argument("--config", default=None, help=help_msg) args, remaining_args = parser.parse_known_args() config_path = None if args.config: config_path = args.config else: default_conf_path = autotools_vars.SYSCONFDIR + "/hatohol/hap2.conf" if os.path.isfile(default_conf_path): config_path = default_conf_path if config_path: parser = hap.ConfigFileParser(config_path, remaining_args, parser) else: #The line enable help message. parser = argparse.ArgumentParser(parents=[parser]) hap.initialize_logger(parser) if config_path: logger.info("Configuration file: %s" % config_path) parser.add_argument("-p", "--disable-poller", action="store_true") parser.add_argument("--polling-targets", nargs="*", choices=haplib.BasePoller.ACTIONS, default=haplib.BasePoller.ACTIONS, help="Names of polloing action. Defaut is all.") help_msg = """ Minimum status logging interval in seconds. The actual interval depends on the implementation and is typically larger than this parameter. """ parser.add_argument("--status-log-interval", type=int, default=600, help=help_msg) self.__transporter_manager = transporter.Manager(default_transporter) self.__transporter_manager.define_arguments(parser) self.__parser = parser self.__main_plugin = None self.__poller = None
def __init__(self, default_transporter="RabbitMQHapiConnector"): self.__error_sleep_time = self.DEFAULT_ERROR_SLEEP_TIME parser = argparse.ArgumentParser() hap.initialize_logger(parser) parser.add_argument("-p", "--disable-poller", action="store_true") help_msg = """ Minimum status logging interval in seconds. The actual interval depends on the implementation and is typically larger than this parameter. """ parser.add_argument("--status-log-interval", type=int, default=600, help=help_msg) self.__transporter_manager = transporter.Manager(default_transporter) self.__transporter_manager.define_arguments(parser) self.__parser = parser self.__main_plugin = None self.__poller = None
def test_define_arguments(self): test_parser = argparse.ArgumentParser() manager = transporter.Manager(None) testutils.assertNotRaises(manager.define_arguments, test_parser)