Utilities

pglift.util.template(bases: str | tuple[tuple[str, ...] | str, ...], *args: str) str

Return the content of a configuration file template, either found in site configuration or in distribution data.

Parameters:
  • bases – The base component(s) of the path where the template file will be looked for; may be a single string or a tuple of string-tuples describing alternative “bases” to look into.

  • args – Final path components of the template file to look for.

Returns:

The content of found template file.

Examples:

Look for ‘postgresql/pg_hba.conf’ in site configuration and then distribution data:

>>> print(template("postgresql", "pg_hba.conf"))
local   all             {surole}                                {auth.local}
local   all             all                                     {auth.local}
host    all             all             127.0.0.1/32            {auth.host}
host    all             all             ::1/128                 {auth.host}

Look for ‘postgresql.conf’ template first in ‘postgresql/16’ directory in site configuration and fall back to ‘postgresql/postgresql.conf’ in distribution data:

>>> print(template((("postgresql", "16"), "postgresql"), "postgresql.conf"))
cluster_name = {name}
shared_buffers = 25%
effective_cache_size = 66%
unix_socket_directories = {settings.socket_directory}
log_directory = {settings.logpath}
log_filename = '{version}-{name}-%Y-%m-%d_%H%M%S.log'
log_destination = 'stderr'
logging_collector = on