Ejemplo n.º 1
0
 def from_predefined(cls,
                     default_template_name=None,
                     autoescape=None,
                     settings=None,
                     **kwargs):
     config = Config.section(
         cls.config_spec,
         settings=settings,
         custom_converters={
             'list_of_template_loc':
             cls.__make_converter__list_of_template_loc(),
         })
     env = Environment(loader=PackageOrFileSystemLoader(
         locations=config['template_locations'],
         encoding=config['template_encoding'],
         fs_followlinks=config['follow_symlinks']),
                       autoescape=(autoescape if autoescape is not None else
                                   DEFAULT_AUTOESCAPE))
     jinja_extensions = sorted(
         set(config['jinja_extensions'] +
             list(kwargs.pop('jinja_extensions', []))))
     return cls(jinja_env=env,
                jinja_extensions=jinja_extensions,
                default_template_name=default_template_name,
                **kwargs)
Ejemplo n.º 2
0
def get_amqp_connection_params_dict(rabbitmq_config_section='rabbitmq'):

    """
    Get the AMQP connection parameters (as a dict) from config.

    Returns:
        A dict that can be used as **kwargs for pika.ConnectionParameters.
    """

    # Config is imported here to avoid circular dependency
    from n6lib.config import Config

    config_spec = RABBITMQ_CONFIG_SPEC_PATTERN.format(
            rabbitmq_config_section=rabbitmq_config_section)
    queue_conf = Config.section(config_spec)
    params_dict = dict(
        host=queue_conf["host"],
        port=queue_conf["port"],
        ssl=queue_conf["ssl"],
        ssl_options={},
        heartbeat_interval=queue_conf['heartbeat_interval'],
    )
    if params_dict['ssl']:
        params_dict['credentials'] = pika.credentials.ExternalCredentials()
        params_dict['ssl_options'].update(
            ca_certs=os.path.expanduser(queue_conf["ssl_ca_certs"]),
            certfile=os.path.expanduser(queue_conf["ssl_certfile"]),
            keyfile=os.path.expanduser(queue_conf["ssl_keyfile"]),
            cert_reqs=ssl.CERT_REQUIRED,
        )
    return params_dict
Ejemplo n.º 3
0
 def __init__(self, **fmt_args):
     self.config = Config.section(self.general_config_spec)
     if self.is_config_spec_or_group_declared():
         self.config.update(self.get_config_section(**fmt_args))
     self.parameters = self.config.copy()
     config_ttl = self.parameters.get(self.config_ttl_opt_name)
     if config_ttl:
         self.parameters[self.parameter_ttl_opt_name] = config_ttl
         del self.parameters[self.config_ttl_opt_name]
     if self.unused_options:
         self.parameters.update({key: None for key in self.unused_options})
     if self.default_none_options:
         self.parameters.update({key: None for key in self.default_none_options
                                 if key not in self.parameters})
Ejemplo n.º 4
0
def get_amqp_connection_params_dict(rabbitmq_config_section='rabbitmq'):
    """
    Get the AMQP connection parameters (as a dict) from config.

    Returns:
        A dict that can be used as **kwargs for pika.ConnectionParameters.
    """

    # Config is imported here to avoid circular dependency
    from n6lib.config import Config

    config_spec = RABBITMQ_CONFIG_SPEC_PATTERN.format(
        rabbitmq_config_section=rabbitmq_config_section)
    queue_conf = Config.section(config_spec)
    return get_amqp_connection_params_dict_from_args(
        host=queue_conf["host"],
        port=queue_conf["port"],
        heartbeat_interval=queue_conf["heartbeat_interval"],
        ssl=queue_conf["ssl"],
        ca_certs=queue_conf.get("ssl_ca_certs", None),
        certfile=queue_conf.get("ssl_certfile", None),
        keyfile=queue_conf.get("ssl_keyfile", None))
Ejemplo n.º 5
0
def get_pipeline_binding_states(pipeline_group,
                                pipeline_name,
                                pipeline_config_section='pipeline'):
    """
    Get the list of "binding states" for the component, or its group,
    from the pipeline config. Pipeline config for an individual
    component has a priority over group's config.

    Args:
        `pipeline_group`:
            A group which the component is bound to.
        `pipeline_name`:
            Name of the component in the pipeline config format,
            which is, by default, a lowercase component's
            class' name.
        `pipeline_config_section`:
            Name of the pipeline config section, "pipeline"
            by default.

    Returns:
        The list of "binding states" for the component, or None,
        if no config option could be found.
    """
    from n6lib.config import Config

    config_spec = PIPELINE_CONFIG_SPEC_PATTERN.format(
        pipeline_config_section=pipeline_config_section)
    pipeline_conf = Config.section(config_spec,
                                   default_converter='list_of_str')
    try:
        return pipeline_conf[pipeline_name]
    except KeyError:
        pass
    try:
        return pipeline_conf[pipeline_group]
    except KeyError:
        return None