#!/usr/bin/env python3 """List the enabled Evolution Data Server address books as JSON. Only reads the source registry (no book connections), so it's fast. The app uses this to know which ~/.cache/evolution/addressbook//cache.db files are live, and what they're called. """ import json import sys import gi gi.require_version("EDataServer", "1.2") from gi.repository import EDataServer as EDS # noqa: E402 reg = EDS.SourceRegistry.new_sync(None) out = [] for s in reg.list_enabled(EDS.SOURCE_EXTENSION_ADDRESS_BOOK): ext = s.get_extension(EDS.SOURCE_EXTENSION_ADDRESS_BOOK) parent = reg.ref_source(s.get_parent()) if s.get_parent() else None out.append({ "uid": s.get_uid(), "name": s.get_display_name(), "backend": ext.get_backend_name(), "account": parent.get_display_name() if parent else "", }) json.dump(out, sys.stdout)