gws.config.util

Helpers for configure methods: create common children and find providers.

Source code: gws.config.util

Module Contents

gws.config.util.configure_database_provider_for(obj: gws.Node, ext_type: str | None = None) → bool

Set the database provider of an object.

The provider is looked up by the dbUid config, then taken from the internal _defaultDb config, then found by the extension type. The result is stored in obj.db.

Parameters:
  • obj – Object to configure.

  • ext_type – Extension type of the provider, e.g. postgres. Defaults to the object’s extType.

Returns:

True if a provider was set.

Raises:

gws.Error – If dbUid is configured but not found, or if no provider is found.

gws.config.util.configure_finders_for(obj: gws.Node, with_default=False) → bool

Create the finders of an object.

Finders are created from the finders config, using the object’s create_finder method if it has one. The result is stored in obj.finders.

Parameters:
  • obj – Object to configure.

  • with_default – If no finders are configured, create one finder with an empty config.

Returns:

True if finders are configured or a default finder was created.

gws.config.util.configure_models_for(obj: gws.Node, with_default=False) → bool

Create the models of an object.

Models are created from the models config, using the object’s create_model method if it has one. The result is stored in obj.models.

Parameters:
  • obj – Object to configure.

  • with_default – If no models are configured, create one model with an empty config.

Returns:

True if models are configured or a default model was created.

gws.config.util.configure_provider_for(obj: gws.Node, cls: type) → bool

Set the provider of an object.

If provider is configured, a shared provider object is created from it. Otherwise, the internal _defaultProvider config is used, if it is an instance of cls. The result is stored in obj.provider.

Parameters:
  • obj – Object to configure.

  • cls – Provider class.

Returns:

True if a provider was set.

Raises:

gws.Error – If no provider is found.

gws.config.util.configure_source_layers_for(obj: gws.Node, layers: list[gws.SourceLayer], is_group: bool = None, is_image: bool = None, is_queryable: bool = None, is_visible: bool = None) → bool

Select the source layers of an object.

If sourceLayers is configured, it is used as a filter on layers. Otherwise, the internal _defaultSourceLayers config is used as is, if set. Otherwise, layers are filtered by the given flags. The result is stored in obj.sourceLayers.

Parameters:
  • obj – Object to configure.

  • layers – Source layers to select from.

  • is_group – Filter by the group flag.

  • is_image – Filter by the image flag.

  • is_queryable – Filter by the queryable flag.

  • is_visible – Filter by the visible flag.

Returns:

Always True.

gws.config.util.configure_templates_for(obj: gws.Node, extra: list | None = None) → bool

Create the templates of an object.

Templates are created from the templates config and from extra, using the object’s create_template method if it has one. The result is stored in obj.templates.

Parameters:
  • obj – Object to configure.

  • extra – Additional template configs, appended after the configured ones.

Returns:

True if at least one template was created.