univention.config_registry package

Contents

univention.config_registry package#

Univention Configuration Registry module.

univention.config_registry.ucr_factory() ConfigRegistry[source]#

Factory method to return private loaded UCR instance.

Returns:

A private UCR instance.

Submodules#

univention.config_registry.backend module#

Univention Configuration Registry backend for data storage.

class univention.config_registry.backend.ConfigRegistry(filename: str = '', write_registry: int = 1)[source]#

Bases: ReadOnlyConfigRegistry, MutableMapping

Merged persistent value store. This is a merged view of several sub-registries.

Parameters:
  • filename – File name for custom layer text database file.

  • write_registry – The UCR level used for writing.

save() None[source]#

Save registry to file.

lock() None[source]#

Lock registry file.

unlock() None[source]#

Un-lock registry file.

clear() None[source]#

Clear all registry keys.

update(changes: dict[str, str | None]) dict[str, tuple[str | None, str | None]][source]#

Set or unset the given config registry variables.

Parameters:

changes – dictionary of ucr-variable-name: value-or-None.

Returns:

A mapping from UCR variable name to a 2-tuple (old-value, new-value)

setdefault(key: str, default: str) str[source]#

Set value for variable only when not yet set.

Parameters:
  • key – UCR variable name.

  • default – UCR variable value.

Returns:

The old value, if the variable was not yet set, otherwise the new value.

exception univention.config_registry.backend.StrictModeException[source]#

Bases: Exception

Attempt to store non-UTF-8 characters in strict UTF-8 mode.

univention.config_registry.backend.exception_occured(out: ~typing.IO = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>) NoReturn[source]#

Print exception message and exit.

Parameters:

out – Output stream for message.

univention.config_registry.filters module#

Univention Configuration Registry output filters.

univention.config_registry.filters.filter_keys_only(args: Any, text: Iterable[str]) Iterable[str][source]#

Filter output: strip values.

Parameters:
  • args – UNUSED.

  • text – Text as list of lines.

Returns:

Filteres list of lines.

univention.config_registry.filters.filter_shell(args: Any, text: Iterable[str]) Iterable[str][source]#

Filter output for shell: escape keys.

Parameters:
  • args – UNUSED.

  • text – Text as list of lines.

Returns:

Filteres list of lines.

univention.config_registry.filters.filter_sort(args: Any, text: Iterable[str]) Iterable[str][source]#

Filter output: sort by key.

Parameters:
  • args – UNUSED.

  • text – Text as list of lines.

Returns:

Filteres list of lines.

univention.config_registry.frontend module#

Univention Configuration Registry command line implementation.

exception univention.config_registry.frontend.UnknownKeyException(value)[source]#

Bases: Exception

Query for unknown key: no info file nor set.

univention.config_registry.frontend.handler_commit(args: list[str], opts: dict[str, Any] = {}) None[source]#

Commit all registered templated files.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_dump(args: list[str], opts: dict[str, Any] = {}) Iterator[str][source]#

Dump all variables.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_filter(args: list[str], opts: dict[str, Any] = {}) None[source]#

Run filter on STDIN to STDOUT.

univention.config_registry.frontend.handler_get(args: list[str], opts: dict[str, Any] = {}) Iterator[str][source]#

Return config registry variable.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_help(args: list[str], opts: dict[str, ~typing.Any] = {}, out: ~typing.IO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None[source]#

Print config registry command line usage.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_info(args: list[str], opts: dict[str, Any] = {}) Iterator[str][source]#

Print variable info.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_register(args: list[str], opts: dict[str, Any] = {}) None[source]#

Register new .info file.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

Search for registry variable.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_set(args: list[str], opts: dict[str, Any] = {}, quiet: bool = False) None[source]#

Set config registry variables in args. Args is an array of strings ‘key=value’ or ‘key?value’.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

  • quiet – Hide output.

univention.config_registry.frontend.handler_unregister(args: list[str], opts: dict[str, Any] = {}) None[source]#

Unregister old .info file.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_unset(args: list[str], opts: dict[str, Any] = {}) None[source]#

Unset config registry variables in args.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_update(args: list[str], opts: dict[str, Any] = {}) None[source]#

Update handlers.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.handler_version(args: list[str], opts: dict[str, Any] = {}) NoReturn[source]#

Print version info.

Parameters:
  • args – Command line arguments.

  • opts – Command line options.

univention.config_registry.frontend.main(args: list[str]) int[source]#

Run config registry.

univention.config_registry.handler module#

Univention Configuration Registry handlers.

class univention.config_registry.handler.ConfigHandlers[source]#

Bases: object

Manage handlers for configuration variables.

CACHE_FILE = '/var/cache/univention-config/cache'#
VERSION = 3#
VERSION_MIN = 3#
VERSION_MAX = 3#
VERSION_TEXT = 'univention-config cache, version'#
VERSION_NOTICE = 'univention-config cache, version 3\n'#
VERSION_RE = re.compile('^univention-config cache, version (?P<version>[0-9]+)$')#
load() None[source]#

Load cached .info data or force update.

get_handler(entry: Mapping[str, list[str]]) ConfigHandler | None[source]#

Parse entry and return Handler instance.

Parameters:

entry.info file entry dictionary.

Returns:

An instance of None.

update() set[ConfigHandler][source]#

Parse all .info files to build list of handlers.

Returns:

Set of all handlers.

update_divert(handlers: Iterable[ConfigHandler]) None[source]#

Synchronize diversions with handlers.

Parameters:

handlers – List of handlers.

register(package: str, ucr: Mapping[str, str]) set[ConfigHandler][source]#

Register new info file for package.

Parameters:
  • package – Name of the package to register.

  • ucr – UCR instance.

Returns:

Set of (new) handlers.

unregister(package: str, ucr: Mapping[str, str]) set[ConfigHandler][source]#

Un-register info file for package.

Parameters:
  • package – Name of the package to un-register.

  • ucr – UCR instance.

Returns:

Set of (then obsolete) handlers.

commit(ucr: Mapping[str, str], filelist: Iterable[str] = []) None[source]#

Call handlers to (re-)generate files.

Parameters:
  • ucr – UCR instance.

  • filelist – List of files to re-generate. By default all files will be re-generated and all modules and scripts will we re-invoked!

call_handler(ucr: Mapping[str, str], handler: ConfigHandler) None[source]#

Call handler passing current configuration variables.

Parameters:
  • ucr – UCR instance.

  • handler – The handler to call.

univention.config_registry.interfaces module#

Handle UCR network configuration.

class univention.config_registry.interfaces.Interfaces(ucr: Mapping[str, str] | None = None)[source]#

Bases: object

Handle network interfaces configured by UCR.

Parameters:

ucr – UCR instance.

property all_interfaces: Iterator[tuple[str, _Iface]]#

Yield IPv4 interfaces.

property ipv4_interfaces: Iterator[tuple[str, _Iface]]#

Yield IPv4 interfaces.

property ipv6_interfaces: Iterator[tuple[_Iface, str]]#

Yield names of IPv6 interfaces.

get_default_ip_address() _IPAddressBase | None[source]#

returns the default IP address.

get_default_ipv4_address() IPv4Interface | None[source]#

returns the default IPv4 address.

get_default_ipv6_address() IPv6Interface | None[source]#

returns the default IPv6 address.

univention.config_registry.interfaces.cmp_alnum(value: str) tuple[source]#

Sort value split by digits / non-digits.

Parameters:

value – The value to sort.

Returns:

value split into tuple.

univention.config_registry.interfaces.forgiving(translation: dict[type[Exception], Any] | None = None) Callable[[Callable], Callable][source]#

Decorator to translate exceptions into return values.

Parameters:

translation – Mapping from Exception class to return value.

univention.config_registry.misc module#

Univention Configuration Registry helper functions.

univention.config_registry.misc.directory_files(directory: str) list[str][source]#

Return a list of all files below the given directory.

Parameters:

directory – Base directory path.

Returns:

List of absolute file names.

univention.config_registry.misc.escape_value(s)#

Return a shell-escaped version of the string s.

univention.config_registry.misc.key_shell_escape(line: str) str[source]#

Escape variable name by substituting shell invalid characters by ‘_’.

Parameters:

line – UCR variable name.

Returns:

substitued variable name

univention.config_registry.misc.replace_dict(line: str, dictionary: dict[str, str]) str[source]#

Map any character from line to its value from dictionary.

>>> replace_dict('kernel', {'e': 'E', 'k': '', 'n': 'pp'})
'ErppEl'
univention.config_registry.misc.replace_umlaut(line: str) str[source]#

Replace german umlauts.

>>> replace_umlaut(u'überschrieben') == u'ueberschrieben'
True
univention.config_registry.misc.validate_key(key: str, out: ~typing.IO = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>) bool[source]#

Check if key consists of only shell valid characters.

Parameters:
  • key – UCR variable name to check.

  • out – Output stream where error message is printed to.

Returns:

True if the name is valid, False otherwise.

univention.config_registry.validation module#

UCR type validation classes.

Checks validity of type definitions and type compatibility of values to be set.

class univention.config_registry.validation.BaseValidator(attrs: dict[str, str])[source]#

Bases: object

Base class for UCR type validators.

NAME = ''#
is_valid(value: str) bool[source]#

Check if value is valid.

Returns:

True if valid, False otherwise.

validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.String(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “str”.

Supports a Python compatible regular expression defined in the optional regex constraints

NAME = 'str'#
REGEX: Pattern | None = None#
property regex: str | None#
validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.URLHttp(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “url_http”.

NAME = 'url_http'#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.URLProxy(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “url_proxy”.

NAME = 'url_proxy'#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.IPv4Address(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “ipv4address”.

NAME = 'ipv4address'#
validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.IPv6Address(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “ipv6address”.

NAME = 'ipv6address'#
validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.IPAddress(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “ipaddress”.

NAME = 'ipaddress'#
validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.Integer(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “int”.

Supports optional ‘min’ and ‘max’ constraints

NAME = 'int'#
MIN: int | None = None#
MAX: int | None = None#
property min: int | None#
property max: int | None#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.UnsignedNumber(attrs: dict[str, str])[source]#

Bases: Integer

Validator for UCR type “uint”.

NAME = 'uint'#
MIN: int | None = 0#
class univention.config_registry.validation.PositiveNumber(attrs: dict[str, str])[source]#

Bases: Integer

Validator for UCR type “pint”.

NAME = 'pint'#
MIN: int | None = 1#
class univention.config_registry.validation.PortNumber(attrs: dict[str, str])[source]#

Bases: Integer

Validator for UCR type “portnumber”.

NAME = 'portnumber'#
MIN: int | None = 0#
MAX: int | None = 65535#
class univention.config_registry.validation.Bool(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “bool”.

NAME = 'bool'#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.Json(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “json”.

NAME = 'json'#
validate(value: str) Any[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.List(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “list”.

NAME = 'list'#
DEFAULT_SEPARATOR = ','#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.Cron(attrs: dict[str, str])[source]#

Bases: BaseValidator

Validator for UCR type “cron”.

NAME = 'cron'#
PREDEFINED = frozenset({'@annually', '@daily', '@hourly', '@monthly', '@reboot', '@weekly', '@yearly'})#
MONTHS = frozenset({'apr', 'aug', 'dec', 'feb', 'jan', 'jul', 'jun', 'mar', 'may', 'nov', 'oct', 'sep'})#
DAYS = frozenset({'fri', 'mon', 'sat', 'sun', 'thu', 'tue', 'wed'})#
validate(value: str) bool[source]#

Check is value is valid.

Returns:

something that can be evaulated with bool().

Raises:

Exception – on errors.

class univention.config_registry.validation.Type(vinfo: Variable)[source]#

Bases: object

Basic UCR type validation class.

Usage:

try:
        validator = Type(vinfo)
except (TypeError, ValueError):
        # invalid type
else:
        if validator.check(value_to_be_set):
                # check ok: set value
        else:
                # value is not compatible with type definition
TYPE_CLASSES: dict[str | None, type[BaseValidator]] = {'bool': <class 'univention.config_registry.validation.Bool'>, 'cron': <class 'univention.config_registry.validation.Cron'>, 'int': <class 'univention.config_registry.validation.Integer'>, 'ipaddress': <class 'univention.config_registry.validation.IPAddress'>, 'ipv4address': <class 'univention.config_registry.validation.IPv4Address'>, 'ipv6address': <class 'univention.config_registry.validation.IPv6Address'>, 'json': <class 'univention.config_registry.validation.Json'>, 'list': <class 'univention.config_registry.validation.List'>, 'pint': <class 'univention.config_registry.validation.PositiveNumber'>, 'portnumber': <class 'univention.config_registry.validation.PortNumber'>, 'str': <class 'univention.config_registry.validation.String'>, 'uint': <class 'univention.config_registry.validation.UnsignedNumber'>, 'url_http': <class 'univention.config_registry.validation.URLHttp'>, 'url_proxy': <class 'univention.config_registry.validation.URLProxy'>}#
check(value: str) bool[source]#