Exemple #1
0
def setup_logging(config_uri):
    """Include-aware Python logging setup from INI config file.
    """
    path, _ = _getpathsec(config_uri, None)
    parser = IncludeAwareConfigParser()
    parser.read([path])

    if parser.has_section('loggers'):
        config_file = os.path.abspath(path)
        defaults = dict(parser, here=os.path.dirname(config_file))
        return fileConfig(parser, defaults)
Exemple #2
0
def setup_logging(config_uri):
    """Include-aware Python logging setup from INI config file.
    """
    path, _ = _getpathsec(config_uri, None)
    parser = IncludeAwareConfigParser()
    parser.read([path])

    if parser.has_section('loggers'):
        config_file = os.path.abspath(path)
        defaults = dict(parser, here=os.path.dirname(config_file))
        return fileConfig(parser, defaults)
Exemple #3
0
    def read_configuration(self) -> dict:
        """Load Celery config from Pyramid INI file.

        We need to be able to do this without ramping up full Websauna, because that's the order of the evens Celery worker wants. This way we avoid circular dependencies during Celery worker start up.
        """
        config = IncludeAwareConfigParser()
        config.read(ini_file)

        # TODO: We have ugly app:main hardcode hack here
        value = config.get("app:main", "websauna.celery_config")
        if not value:
            raise RuntimeError("Could not find websauna.celery_config in {}".format(ini_file))

        config = parse_celery_config(value)
        return config
Exemple #4
0
    def read_configuration(self) -> dict:
        """Load Celery config from Pyramid INI file.

        We need to be able to do this without ramping up full Websauna, because that's the order of the evens Celery worker wants. This way we avoid circular dependencies during Celery worker start up.
        """
        config = IncludeAwareConfigParser()
        config.read(ini_file)

        # TODO: We have ugly app:main hardcode hack here
        value = config.get("app:main", "websauna.celery_config")
        if not value:
            raise RuntimeError("Could not find websauna.celery_config in {}".format(ini_file))

        config = parse_celery_config(value)
        return config
Exemple #5
0
    def __init__(self, global_config: dict, settings: Optional[dict] = None):
        """
        :param global_config: Dictionary as passed to WSGI entry point.

        :param settings: DEPRECATED. Extra settings as passed to WSGI entry point. TODO: How to handle these?
        """
        if not settings:
            settings = IncludeAwareConfigParser.retrofit_settings(
                global_config)

        #: This is the refer    ence to the config file which started our process. We need to later pass it to Notebook.
        settings["websauna.global_config"] = global_config
        self.global_config = global_config

        #: Reference to Celery app instance
        self.celery = None

        self.settings = settings
        self.config = self.create_configurator()

        self.config.registry.static_asset_policy = self.static_asset_policy = self.create_static_asset_policy(
        )

        #: Flag to tell if we need to do sanity check for redis sessiosn
        self._has_redis_sessions = False

        #: This flag keeps state if the initializer has been run or not.
        self._already_run = False

        # Exposed Websauna features
        self.config.registry.features = set()
Exemple #6
0
    def __init__(self, global_config:dict, settings:dict=None):
        """
        :param global_config: Dictionary as passed to WSGI entry point.

        :param settings: DEPRECATED. Extra settings as passed to WSGI entry point. TODO: How to handle these?
        """
        if not settings:
            settings = IncludeAwareConfigParser.retrofit_settings(global_config)

        #: This is the refer    ence to the config file which started our process. We need to later pass it to Notebook.
        settings["websauna.global_config"] = global_config
        self.global_config = global_config

        #: Reference to Celery app instance
        self.celery = None

        self.settings = settings
        self.config = self.create_configurator()

        self.config.registry.static_asset_policy = self.static_asset_policy = self.create_static_asset_policy()

        #: Flag to tell if we need to do sanity check for redis sessiosn
        self._has_redis_sessions = False

        #: This flag keeps state if the initializer has been run or not.
        self._already_run = False
Exemple #7
0
    def __init__(self, global_config:dict, settings:dict=None, configurator:Configurator=None):
        """

        :param global_config: Dictionary as passed to WSGI entry point.

        :param settings: DEPRECATED. Extra settings as passed to WSGI entry point. TODO: How to handle these?

        :param config: Configurator passed by another Pyramid app entry point. If given use this. If not given extra the config file from ``global_config`` and then create a ``Configurator`` for it. This is usually given when Initializer is used with addon.
        """
        if not settings:
            settings = IncludeAwareConfigParser.retrofit_settings(global_config)

        #: This is the refer    ence to the config file which started our process. We need to later pass it to Notebook.
        settings["websauna.global_config"] = global_config
        self.global_config = global_config

        self.config = self.create_configurator(settings)

        #: Python module which provides Horus models
        self.user_models_module = None

        #: Reference to Celery app instance
        self.celery = None

        self.settings = settings

        #: Flag to tell if we need to do sanity check for redis sessiosn
        self._has_redis_sessions = False
Exemple #8
0
def browser(request, browser_instance_getter, ini_settings) -> Browser:
    """Websauna specic browser fixtures.

    This is a py.test fixture to create a :term:`pytest-splinter` based browser instance. It is configured with splinter settings from an INI ``[splinter]`` section.

    .. note ::

        These will override any command line options given.

    .. note ::

        This is a temporary mechanism and will be phased out with INI based configuration.

    Example in ``test.ini``::

        [splinter]
        make_screenshot_on_failure = false

    For list of possible settings see this function source code.

    More information

    * https://github.com/pytest-dev/pytest-splinter/blob/master/pytest_splinter/plugin.py
    """

    splinter_command_line_args = [
        "splinter_session_scoped_browser",
        "splinter_browser_load_condition",
        "splinter_browser_load_timeout",
        "splinter_download_file_types",
        "splinter_driver_kwargs",
        "splinter_file_download_dir",
        "splinter_firefox_profile_preferences",
        "splinter_firefox_profile_directory",
        "splinter_make_screenshot_on_failure",
        "splinter_remote_url",
        "splinter_screenshot_dir",
        "splinter_selenium_implicit_wait",
        "splinter_wait_time",
        "splinter_selenium_socket_timeout",
        "splinter_selenium_speed",
        "splinter_webdriver_executable",
        "splinter_window_size",
        "splinter_browser_class",
        "splinter_clean_cookies_urls",
    ]

    # Cache read settings on a function attribute
    full_config = getattr(browser, "full_config", None)
    if not full_config:
        parser = IncludeAwareConfigParser()
        parser.read(ini_settings["_ini_file"])
        full_config = browser.full_config = parser

    # If INI provides any settings override splinter defaults
    for arg in splinter_command_line_args:
        ini_setting_name = arg.replace("splinter_", "")
        # Read setting from splinter section
        arg_value = full_config.get("splinter",
                                    ini_setting_name,
                                    fallback=None)
        if arg_value:
            setattr(request.config.option, arg, arg_value)

    return browser_instance_getter(request, browser)
Exemple #9
0
def browser(request, browser_instance_getter, ini_settings) -> Browser:
    """Websauna specic browser fixtures.

    This is a py.test fixture to create a :term:`pytest-splinter` based browser instance. It is configured with splinter settings from an INI ``[splinter]`` section.

    .. note ::

        These will override any command line options given.

    .. note ::

        This is a temporary mechanism and will be phased out with INI based configuration.

    Example in ``test.ini``::

        [splinter]
        make_screenshot_on_failure = false

    For list of possible settings see this function source code.

    More information

    * https://github.com/pytest-dev/pytest-splinter/blob/master/pytest_splinter/plugin.py
    """

    splinter_command_line_args = [
        "splinter_session_scoped_browser",
        "splinter_browser_load_condition",
        "splinter_browser_load_timeout",
        "splinter_download_file_types",
        "splinter_driver_kwargs",
        "splinter_file_download_dir",
        "splinter_firefox_profile_preferences",
        "splinter_firefox_profile_directory",
        "splinter_make_screenshot_on_failure",
        "splinter_remote_url",
        "splinter_screenshot_dir",
        "splinter_selenium_implicit_wait",
        "splinter_wait_time",
        "splinter_selenium_socket_timeout",
        "splinter_selenium_speed",
        "splinter_webdriver_executable",
        "splinter_window_size",
        "splinter_browser_class",
        "splinter_clean_cookies_urls",
    ]

    # Cache read settings on a function attribute
    full_config = getattr(browser, "full_config", None)
    if not full_config:
        parser = IncludeAwareConfigParser()
        parser.read(ini_settings["_ini_file"])
        full_config = browser.full_config = parser

    # If INI provides any settings override splinter defaults
    for arg in splinter_command_line_args:
        ini_setting_name = arg.replace("splinter_", "")
        # Read setting from splinter section
        arg_value = full_config.get("splinter", ini_setting_name, fallback=None)
        if arg_value:
            setattr(request.config.option, arg, arg_value)

    return browser_instance_getter(request, browser)