khard.config
============

.. py:module:: khard.config

.. autoapi-nested-parse::

   Loading and validation of the configuration file



Attributes
----------

.. autoapisummary::

   khard.config.logger
   khard.config.ConfigFile


Classes
-------

.. autoapisummary::

   khard.config.Config


Functions
---------

.. autoapisummary::

   khard.config.validate_command
   khard.config.validate_action
   khard.config.validate_private_objects


Module Contents
---------------

.. py:data:: logger

.. py:data:: ConfigFile

.. py:function:: 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.

   :param value: the config value to validate
   :returns: the command after validation
   :raises: validate.ValidateError


.. py:function:: validate_action(value: str) -> str

   Check that the given value is a valid action.

   :param value: the config value to check
   :returns: the same value
   :raises: validate.ValidateError


.. py:function:: validate_private_objects(value: list[str]) -> list[str]

   Check that the private objects are reasonable

   :param value: the config value to check
   :returns: the list of private objects
   :raises: validate.ValidateError


.. py:class:: Config(config_file: ConfigFile | None = None)

   Parse and validate the config file with configobj.


   .. py:attribute:: supported_vcard_versions
      :value: ('3.0', '4.0')



   .. py:attribute:: config
      :type:  configobj.ConfigObj


   .. py:attribute:: abooks
      :type:  khard.address_book.AddressBookCollection


   .. py:method:: _load_config_file(config_file: ConfigFile | None) -> configobj.ConfigObj
      :classmethod:


      Find and load the config file.

      :param config_file: the path to the config file to load
      :returns: the loaded config file



   .. py:method:: _validate(config: configobj.ConfigObj) -> configobj.ConfigObj
      :staticmethod:



   .. py:method:: _unfold_discover_books(addressbooks: configobj.Section) -> configobj.Section
      :classmethod:


      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.

      :param config: the configuration to be changed
      :returns: the changed configuration with no "discover" addressbooks



   .. py:method:: _find_leaf_dirs(hits: Iterable[str]) -> set[str]
      :staticmethod:


      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.

      :param hits: the hits of a glob as returned by glob.iglob
      :returns: a set of path strings



   .. py:method:: _set_attributes() -> None

      Set the attributes from the internal config instance on self.



   .. py:method:: 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.



   .. py:method:: get_address_books(names: Iterable[str], queries: dict[str, khard.query.Query]) -> khard.address_book.AddressBookCollection

      Load all address books with the given names.

      :param names: the address books to load
      :param queries: a mapping of address book names to search queries
      :returns: the loaded address books



   .. py:method:: merge(other: configobj.ConfigObj | dict) -> None

      Merge the config with some other dict or ConfigObj

      :param other: the other dict or ConfigObj to merge into self
      :returns: None



   .. py:method:: merge_args(args: argparse.Namespace) -> None

      Merge options from a flat argparse object.

      :param args: the parsed arguments to incorporate



