From c77821199205f44d978ffc0bedb337ff51f16937 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 17 Aug 2024 16:51:45 +0530 Subject: [PATCH] Document the annotations API at least cursorily --- src/calibre/db/cache.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 34e04d83cd..10a9c48625 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -3185,6 +3185,9 @@ class Cache: @read_api def annotations_map_for_book(self, book_id, fmt, user_type='local', user='viewer'): + ''' + Return a map of annotation type -> annotation data for the specified book_id, format, user and user_type. + ''' ans = {} for annot in self.backend.annotations_for_book(book_id, fmt, user_type, user): ans.setdefault(annot['type'], []).append(annot) @@ -3192,22 +3195,40 @@ class Cache: @read_api def all_annotations_for_book(self, book_id): + ''' + Return a tuple containing all annotations for the specified book_id as a dict with keys: + `format`, `user_type`, `user`, `annotation`. Here, annotation is the annotation data. + ''' return tuple(self.backend.all_annotations_for_book(book_id)) @read_api def annotation_count_for_book(self, book_id): + ''' + Return the number of annotations for the specified book available in the database. + ''' return self.backend.annotation_count_for_book(book_id) @read_api def all_annotation_users(self): + ''' + Return a tuple of all (user_type, user name) that have annotations. + ''' return tuple(self.backend.all_annotation_users()) @read_api def all_annotation_types(self): + ''' + Return a tuple of all annotation types in the database. + ''' return tuple(self.backend.all_annotation_types()) @read_api def all_annotations(self, restrict_to_user=None, limit=None, annotation_type=None, ignore_removed=False, restrict_to_book_ids=None): + ''' + Return a tuple of all annotations matching the specified criteria. + `ignore_removed` controls whether removed (deleted) annotations are also returned. Removed annotations are just a skeleton + used for merging of annotations. + ''' return tuple(self.backend.all_annotations(restrict_to_user, limit, annotation_type, ignore_removed, restrict_to_book_ids)) @read_api @@ -3223,6 +3244,9 @@ class Cache: restrict_to_user=None, ignore_removed=False ): + ''' + Return of a tuple of annotations matching the specified Full-text query. + ''' return tuple(self.backend.search_annotations( fts_engine_query, use_stemming, highlight_start, highlight_end, snippet_size, annotation_type, restrict_to_book_ids, restrict_to_user, @@ -3231,10 +3255,16 @@ class Cache: @write_api def delete_annotations(self, annot_ids): + ''' + Delete annotations with the specified ids. + ''' self.backend.delete_annotations(annot_ids) @write_api def update_annotations(self, annot_id_map): + ''' + Update annotations. + ''' self.backend.update_annotations(annot_id_map) @write_api @@ -3252,10 +3282,16 @@ class Cache: @write_api def set_annotations_for_book(self, book_id, fmt, annots_list, user_type='local', user='viewer'): + ''' + Set all annotations for the specified book_id, fmt, user_type and user. + ''' self.backend.set_annotations_for_book(book_id, fmt, annots_list, user_type, user) @write_api def merge_annotations_for_book(self, book_id, fmt, annots_list, user_type='local', user='viewer'): + ''' + Merge the specified annotations into the existing annotations for book_id, fm, user_type, and user. + ''' from calibre.utils.date import EPOCH from calibre.utils.iso8601 import parse_iso8601 amap = self._annotations_map_for_book(book_id, fmt, user_type=user_type, user=user)