Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(28)  |  Call(14)  |  Derive(0)  |  Import(14)
Initialize settings management system. This function available
as pyramid configurator directive. You should call it during
application configuration process.

.. code-block:: python

  config = Configurator()
  config.include('ptah')

  # initialize ptah setting management system(more...)

        def init_settings(pconfig, cfg=None, section=configparser.DEFAULTSECT):
    """Initialize settings management system. This function available
    as pyramid configurator directive. You should call it during
    application configuration process.

    .. code-block:: python

      config = Configurator()
      config.include('ptah')

      # initialize ptah setting management system
      config.ptah_init_settings()

    """
    settings = config.get_cfg_storage(SETTINGS_OB_ID, pconfig.registry,Settings)

    if settings.initialized:
        raise RuntimeError(
            "initialize_settings has been called more than once.")

    log.info('Initializing ptah settings')

    settings.initialized = True

    if cfg is None:
        cfg = pconfig.registry.settings

    here = cfg.get('here', './')
    include = cfg.get('include', '')
    for f in include.split('\n'):
        f = f.strip()
        if f and os.path.exists(f):
            parser = configparser.SafeConfigParser()
            parser.read(f)
            if section == configparser.DEFAULTSECT or \
                    parser.has_section(section):
                cfg.update(parser.items(section, vars={'here': here}))

    pconfig.begin()
    try:
        settings.init(pconfig, cfg)
        pconfig.registry.notify(
            ptah.events.SettingsInitializing(pconfig, pconfig.registry))
        pconfig.registry.notify(
            ptah.events.SettingsInitialized(pconfig, pconfig.registry))
    except Exception as e:
        raise StopException(e)
    finally:
        pconfig.end()
        


src/p/t/ptah-0.8.0/ptah/tests/test_settings.py   ptah(Download)
    def test_settings_initialize_events(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
 
        sm.registerHandler(h2, (ptah.events.SettingsInitialized,))
 
        init_settings(self.config, {})
 
        self.assertTrue(isinstance(events[0], ptah.events.SettingsInitializing))
    def test_settings_initialize_events_exceptions(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
 
        err = None
        try:
            init_settings(self.config, {})
        except Exception as exc:
            err = exc
    def test_settings_initialize_only_once(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
        init_settings(self.config, {})

src/p/t/ptah-HEAD/ptah/tests/test_settings.py   ptah(Download)
    def test_settings_initialize_events(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
 
        sm.registerHandler(h2, (ptah.events.SettingsInitialized,))
 
        init_settings(self.config, {})
 
        self.assertTrue(isinstance(events[0], ptah.events.SettingsInitializing))
    def test_settings_initialize_events_exceptions(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
 
        err = None
        try:
            init_settings(self.config, {})
        except Exception as exc:
            err = exc
    def test_settings_initialize_only_once(self):
        from ptah.settings import init_settings
 
        self.init_ptah()
        init_settings(self.config, {})