khard.config

Loading and validation of the configuration file

Module Contents

Classes

Config

Parse and validate the config file with configobj.

Functions

validate_command(→ List[str])

Special validator to check shell commands

validate_action(→ str)

Check that the given value is a valid action.

validate_private_objects(→ List[str])

Check that the private objects are reasonable

Attributes

logger

ConfigFile

khard.config.logger
khard.config.ConfigFile
exception khard.config.ConfigError

Bases: Exception

Errors during config file parsing

khard.config.validate_command(value: List[str]) List[str]

Special validator to check shell commands

The input must either be a list of strings or a string that shlex.split can parse into such.

Parameters:

value – the config value to validate

Returns:

the command after validation

Raises:

validate.ValidateError

khard.config.validate_action(value: str) str

Check that the given value is a valid action.

Parameters:

value – the config value to check

Returns:

the same value

Raises:

validate.ValidateError

khard.config.validate_private_objects(value: List[str]) List[str]

Check that the private objects are reasonable

Parameters:

value – the config value to check

Returns:

the list of private objects

Raises:

validate.ValidateError

class khard.config.Config(config_file: ConfigFile | None = None)

Parse and validate the config file with configobj.

supported_vcard_versions = ('3.0', '4.0')
classmethod _load_config_file(config_file: ConfigFile | None) configobj.ConfigObj

Find and load the config file.

Parameters:

config_file – the path to the config file to load

Returns:

the loaded config file

static _validate(config: configobj.ConfigObj) configobj.ConfigObj
_set_attributes() None

Set the attributes from the internal config instance on self.

init_address_books() None

Initialize the internal address book collection.

This method should only be called after merging in the command line options as they can hold some options that are relevant for the loading of the address books.

get_address_books(names: Iterable[str], queries: Dict[str, khard.query.Query]) khard.address_book.AddressBookCollection

Load all address books with the given names.

Parameters:
  • names – the address books to load

  • queries – a mapping of address book names to search queries

Returns:

the loaded address books

merge(other: configobj.ConfigObj | Dict) None

Merge the config with some other dict or ConfigObj

Parameters:

other – the other dict or ConfigObj to merge into self

Returns:

None

merge_args(args: argparse.Namespace) None

Merge options from a flat argparse object.

Parameters:

args (argparse.Namespace) – the parsed arguments to incorporate