Skip to content

Commit 93fcf47

Browse files
committed
docs: add documentation for discover addressbook type
1 parent 96e11b1 commit 93fcf47

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

doc/source/examples/khard.conf.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
path = ~/.contacts/family/
99
[[friends]]
1010
path = ~/.contacts/friends/
11+
[[work]]
12+
path = ~/.work/**/client-*-contacts/
13+
type = discover
1114

1215
[general]
1316
debug = no

doc/source/man/khard.conf.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ addressbooks
4141
This section contains several subsections, but at least one. Each subsection
4242
can have an arbitrary name which will be the name of an addressbook known to
4343
khard. Each of these subsections **must** have a *path* key with the path to
44-
the folder containing the vCard files for that addressbook. The *path* value
45-
supports environment variables and tilde prefixes. :program:`khard` expects
44+
the folder containing the vCard files for that addressbook. Optionally, you
45+
can set the *type* value to either ``discover`` or ``vdir``, the default. The
46+
*path* value supports environment variables and tilde prefixes. When using
47+
the ``discover`` type, it also supports globbing. :program:`khard` expects
4648
the vCard files to hold only one VCARD record each and end in a :file:`.vcf`
4749
extension.
4850

khard/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ def _validate(config: configobj.ConfigObj) -> configobj.ConfigObj:
142142

143143
@classmethod
144144
def _unfold_discover_books(cls, addressbooks: configobj.Section) -> configobj.Section:
145+
"""Expand globs in path of addressbooks of type "discover"
146+
147+
This expands all addressbooks of type "discover" into (potentially)
148+
multiple addressbooks of type "vdir". The names are automatically generated
149+
based on the directory name.
150+
151+
:param config: the configuration to be changed
152+
:returns: the changed configuration with no "discover" addressbooks
153+
"""
145154
for section_name, book in addressbooks.copy().items():
146155
if book["type"] != "discover":
147156
continue
@@ -166,6 +175,14 @@ def _unfold_discover_books(cls, addressbooks: configobj.Section) -> configobj.Se
166175

167176
@staticmethod
168177
def _find_leaf_dirs(hits: Iterable[str]) -> set[str]:
178+
"""Find leaf directories in a tree of hits when using glob.iglob
179+
180+
The hits are neither guaranteed to be unique nor leaf directories, both
181+
of which are enforced by this function.
182+
183+
:param hits: the hits of a glob as returned by glob.iglob
184+
:returns: a set of path strings
185+
"""
169186
dirs = {os.path.normpath(hit) for hit in hits if os.path.isdir(hit)}
170187
parents = {os.path.normpath(os.path.join(dir, os.pardir)) for dir in dirs}
171188
return dirs - parents

0 commit comments

Comments
 (0)