Пример #1
0
def save_annotations(annotations_list, annotations_path_key, bld, pathtoebook,
                     in_book_file, sync_annots_user):
    annots = annot_list_as_bytes(annotations_list)
    with open(os.path.join(annotations_dir, annotations_path_key), 'wb') as f:
        f.write(annots)
    if in_book_file and os.access(pathtoebook, os.W_OK):
        before_stat = os.stat(pathtoebook)
        save_annots_to_epub(pathtoebook, annots)
        update_book(pathtoebook, before_stat,
                    {'calibre-book-annotations.json': annots})
    if bld:
        save_annotations_list_to_library(bld, annotations_list,
                                         sync_annots_user)
Пример #2
0
 def save_annotations(self):
     if not self.current_book_data:
         return
     amap = self.current_book_data['annotations_map']
     annots = as_bytes(serialize_annotations(amap))
     with open(os.path.join(annotations_dir, self.current_book_data['annotations_path_key']), 'wb') as f:
         f.write(annots)
     if self.current_book_data.get('pathtoebook', '').lower().endswith(
             '.epub') and get_session_pref('save_annotations_in_ebook', default=True):
         path = self.current_book_data['pathtoebook']
         if os.access(path, os.W_OK):
             before_stat = os.stat(path)
             save_annots_to_epub(path, annots)
             update_book(path, before_stat, {'calibre-book-annotations.json': annots})