From 1f2b890f10861b920d14fc0e09999b1a753b7fe1 Mon Sep 17 00:00:00 2001 From: Steffen Siebert Date: Sun, 19 Feb 2023 13:28:31 +0100 Subject: [PATCH] Address code review comments --- src/calibre/customize/__init__.py | 11 +++++++---- src/calibre/srv/convert.py | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 8a72ac0c35..8f8c6ccf9c 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -390,8 +390,9 @@ class FileTypePlugin(Plugin): # {{{ def postconvert(self, book_id, book_format, db): ''' - Called post conversion, i.e., after the book file has been added to the database. It is - useful for modifying the book record based on the contents of the newly added file. + Called post conversion, i.e., after the book file has been added to the database. Note that + it is run after a conversion only, not after a book is added. It is useful for modifying + the book record based on the contents of the newly added file. :param book_id: Database id of the added book. :param book_format: The file type of the book that was added. @@ -401,8 +402,10 @@ class FileTypePlugin(Plugin): # {{{ def postdelete(self, book_id, book_format, db): ''' - Called post deletion, i.e., after the book file has been deleted from the database. It is - useful for modifying the book record based on the format of the deleted file. + Called post deletion, i.e., after the book file has been deleted from the database. Note + that it is not run when a book record is deleted, only when one or more formats from the + book are deleted. It is useful for modifying the book record based on the format of the + deleted file. :param book_id: Database id of the added book. :param book_format: The file type of the book that was added. diff --git a/src/calibre/srv/convert.py b/src/calibre/srv/convert.py index b6407b3079..7741913d9b 100644 --- a/src/calibre/srv/convert.py +++ b/src/calibre/srv/convert.py @@ -7,7 +7,7 @@ import shutil import tempfile from threading import Lock -from calibre.customize.ui import input_profiles, output_profiles +from calibre.customize.ui import input_profiles, output_profiles, run_plugins_on_postconvert from calibre.db.errors import NoSuchBook from calibre.srv.changes import formats_added from calibre.srv.errors import BookNotFound, HTTPNotFound @@ -194,6 +194,7 @@ def conversion_status(ctx, rd, job_id): except NoSuchBook: raise HTTPNotFound( f'book_id {job_status.book_id} not found in library') + run_plugins_on_postconvert(db, job_status.book_id, fmt) formats_added({job_status.book_id: (fmt,)}) ans['size'] = os.path.getsize(job_status.output_path) ans['fmt'] = fmt