def test_islocked(self): """ Test the `ipalib.config.Env.__islocked__` method. """ o = self.cls() assert o.__islocked__() is False assert base.islocked(o) is False o.__lock__() assert o.__islocked__() is True assert base.islocked(o) is True
def finalize(self): """ Finalize the registration, instantiate the plugins. `API.bootstrap` will automatically be called if it hasn't been already. """ self.__doing('finalize') self.__do_if_not_done('load_plugins') if self.env.env_confdir is not None: if self.env.env_confdir == self.env.confdir: logger.info("IPA_CONFDIR env sets confdir to '%s'.", self.env.confdir) for plugin in self.__plugins: if not self.env.validate_api: if plugin.full_name not in DEFAULT_PLUGINS: continue else: try: default_version = self.__default_map[plugin.name] except KeyError: pass else: # Technicall plugin.version is not an API version. The # APIVersion class can handle plugin versions. It's more # lean than pkg_resource.parse_version(). version = ipautil.APIVersion(plugin.version) default_version = ipautil.APIVersion(default_version) if version < default_version: continue self.__default_map[plugin.name] = plugin.version production_mode = self.is_production_mode() for base in self.bases: for plugin in self.__plugins: if not any(issubclass(b, base) for b in plugin.bases): continue if not self.env.plugins_on_demand: self._get(plugin) name = base.__name__ if not production_mode: assert not hasattr(self, name) setattr(self, name, APINameSpace(self, base)) for instance in six.itervalues(self.__instances): if not production_mode: assert instance.api is self if not self.env.plugins_on_demand: instance.ensure_finalized() if not production_mode: assert islocked(instance) self.__finalized = True if not production_mode: lock(self)
def finalize(self): """ Finalize the registration, instantiate the plugins. `API.bootstrap` will automatically be called if it hasn't been already. """ self.__doing('finalize') self.__do_if_not_done('load_plugins') if self.env.env_confdir is not None: if self.env.env_confdir == self.env.confdir: self.log.info( "IPA_CONFDIR env sets confdir to '%s'.", self.env.confdir) for plugin in self.__plugins: if not self.env.validate_api: if plugin.full_name not in DEFAULT_PLUGINS: continue else: try: default_version = self.__default_map[plugin.name] except KeyError: pass else: # Technicall plugin.version is not an API version. The # APIVersion class can handle plugin versions. It's more # lean than pkg_resource.parse_version(). version = ipautil.APIVersion(plugin.version) default_version = ipautil.APIVersion(default_version) if version < default_version: continue self.__default_map[plugin.name] = plugin.version production_mode = self.is_production_mode() for base in self.bases: for plugin in self.__plugins: if not any(issubclass(b, base) for b in plugin.bases): continue if not self.env.plugins_on_demand: self._get(plugin) name = base.__name__ if not production_mode: assert not hasattr(self, name) setattr(self, name, APINameSpace(self, base)) for instance in six.itervalues(self.__instances): if not production_mode: assert instance.api is self if not self.env.plugins_on_demand: instance.ensure_finalized() if not production_mode: assert islocked(instance) self.__finalized = True if not production_mode: lock(self)
def finalize(self): """ Finalize the registration, instantiate the plugins. `API.bootstrap` will automatically be called if it hasn't been already. """ self.__doing('finalize') self.__do_if_not_done('load_plugins') for plugin in self.__plugins: if not self.env.validate_api: if plugin.full_name not in DEFAULT_PLUGINS: continue else: try: default_version = self.__default_map[plugin.name] except KeyError: pass else: version = LooseVersion(plugin.version) default_version = LooseVersion(default_version) if version < default_version: continue self.__default_map[plugin.name] = plugin.version production_mode = self.is_production_mode() for base in self.bases: for plugin in self.__plugins: if not any(issubclass(b, base) for b in plugin.bases): continue if not self.env.plugins_on_demand: self._get(plugin) name = base.__name__ if not production_mode: assert not hasattr(self, name) setattr(self, name, APINameSpace(self, base)) for instance in six.itervalues(self.__instances): if not production_mode: assert instance.api is self if not self.env.plugins_on_demand: instance.ensure_finalized() if not production_mode: assert islocked(instance) self.__finalized = True if not production_mode: lock(self)
def finalize(self): """ Finalize the registration, instantiate the plugins. `API.bootstrap` will automatically be called if it hasn't been already. """ self.__doing('finalize') self.__do_if_not_done('load_plugins') production_mode = self.is_production_mode() plugins = {} plugin_info = {} for base in self.bases: name = base.__name__ sub_d = self.__plugins.get(base, {}) members = [] for klass in sub_d.values(): try: instance = plugins[klass] except KeyError: instance = plugins[klass] = klass(self) members.append(instance) plugin_info.setdefault( '%s.%s' % (klass.__module__, klass.__name__), []).append(name) if not production_mode: assert not hasattr(self, name) setattr(self, name, NameSpace(members)) for klass, instance in plugins.items(): if not production_mode: assert instance.api is self if klass.finalize_early or not self.env.plugins_on_demand: instance.ensure_finalized() if not production_mode: assert islocked(instance) self.__finalized = True self.plugins = tuple((k, tuple(v)) for k, v in plugin_info.items()) if not production_mode: lock(self)