def initialize_settings(cfg, pconfig, section=ConfigParser.DEFAULTSECT): settings = pconfig.registry.storage[SETTINGS_OB_ID] if settings.initialized: raise RuntimeError( "initialize_settings has been called more than once.") log.info('Initializing ptah settings') settings.config = pconfig settings.initialized = True 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(cfg) api.notify(SettingsInitializing(pconfig, pconfig.registry)) api.notify(SettingsInitialized(pconfig, pconfig.registry)) except Exception, e: raise api.StopException(e)
def save(self, *args): if self._changed is not None: for grp, attrs in self._changed.items(): api.notify(SettingsGroupModified(self[grp], self.config)) self._changed = None if self.loader is not None: data = self.export() if data: self.loader.save(data)
def initialize_settings(settings, config=None, loader=None, watcherFactory=_marker, section=ConfigParser.DEFAULTSECT): if Settings.initialized: raise RuntimeError( "initialize_settings has been called more than once.") log.info('Initializing ptah settings') Settings.config = config Settings.initialized = True if watcherFactory is _marker: watcherFactory = iNotifyWatcher here = settings.get('here', './') if loader is None: loader = FileStorage( settings.get('settings',''), settings.get('defaults', ''), here, section, watcherFactory) include = settings.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): settings.update(parser.items(section, vars={'here': here})) Settings.init(loader, settings) try: api.notify(SettingsInitializing(config)) api.notify(SettingsInitialized(config)) except Exception, e: raise api.StopException(e)