khard.config¶
Loading and validation of the configuration file
Attributes¶
Classes¶
Parse and validate the config file with configobj. |
Functions¶
|
Special validator to check shell commands |
|
Check that the given value is a valid action. |
|
Check that the private objects are reasonable |
Module Contents¶
- khard.config.logger¶
- khard.config.ConfigFile¶
- 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')¶
- config: configobj.ConfigObj¶
- 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¶
- classmethod _unfold_discover_books(addressbooks: configobj.Section) configobj.Section¶
Expand globs in path of addressbooks of type “discover”
This expands all addressbooks of type “discover” into (potentially) multiple addressbooks of type “vdir”. The names are automatically generated based on the directory name.
- Parameters:
config – the configuration to be changed
- Returns:
the changed configuration with no “discover” addressbooks
- static _find_leaf_dirs(hits: Iterable[str]) set[str]¶
Find leaf directories in a tree of hits when using glob.iglob
The hits are neither guaranteed to be unique nor leaf directories, both of which are enforced by this function.
- Parameters:
hits – the hits of a glob as returned by glob.iglob
- Returns:
a set of path strings
- _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 – the parsed arguments to incorporate