View Single Post
Old 10-21-2018, 07:39 PM   #1
Einix
Junior Member
Einix began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Oct 2018
Device: Moonreader+
Problems with Plugin Demo

Hi all,
I am using calibre for a while now. Love it, Thanks for all the good work. Also thanks for the many plugins.
There are a few things I would like to get done. So I looked into the plugin development. Downloaded the demo code. And voila: It didn't work ?
I tried the simple hello_world __init__.py demo, it seems to update the publisher temporarily, but some doesn't save it permanently.

Then I tried the interface demo. Same effect here.
I added some prints for debugging, I am running under Linux, I changed the demo:

def update_title(self):
'''
Set the metadata in the files in the selected book's record to
match the current metadata in the database.
'''
from calibre.ebooks.metadata.meta import set_metadata, get_metadata
from calibre.gui2 import error_dialog, info_dialog

# Get currently selected books
rows = self.gui.library_view.selectionModel().selectedRow s()
if not rows or len(rows) == 0:
return error_dialog(self.gui, 'Cannot update metadata', 'No books selected', show=True)
# Map the rows to book ids
ids = list(map(self.gui.library_view.model().id, rows))
db = self.db.new_api
for book_id in ids:
# Get the current metadata for this book from the db
mi = db.get_metadata(book_id, get_cover=True, cover_as_data=True)
fmts = db.formats(book_id)
if not fmts:
continue
for fmt in fmts:
# Get a python file object for the format. This will be either
# an in memory file or a temporary on disk file
ffile = db.format(book_id, fmt, as_file=True)
ffile.seek(0)
print ("Original Publisher: ", mi.publisher)


#change value
mi.publisher = "Test Publisher"

# Set metadata in the format
set_metadata(ffile, mi, fmt)
ffile.seek(0)
print ("Updated Publisher: ", mi.publisher)

# Now replace the file in the calibre library with the updated
# file. We dont use add_format_with_hooks as the hooks were
# already run when the file was first added to calibre.
db.add_format(book_id, fmt, ffile, run_hooks=False)

print ("Refreshed Publisher: ", mi.publisher)

info_dialog(self, 'Updated files', 'Updated the metadata in the files of %d book(s)'%len(ids), show=True)

the debug output is:
einix@Eva:~/workspace/interface_demo_plugin> calibre-customize -b . & calibre-debug -g
[1] 20151
calibre 3.27.1 embedded-python: False is64bit: True
Linux-4.12.14-lp150.12.22-default-x86_64-with-glibc2.2.5 Linux ('64bit', '')
('Linux', '4.12.14-lp150.12.22-default', '#1 SMP Sat Oct 13 05:05:16 UTC 2018 (09415e8)')
Python 2.7.14
Linux: ('', '', '')
Interface language: en_GB
Plugin updated: Interface Plugin Demo (1, 0, 0)
Successfully initialized third party plugins: Quality Check (1, 9, 11) && EpubSplit (2, 4, 0) && Interface Plugin Demo (1, 0, 0) && Find Duplicates (1, 6, 3)
Not controlling automatic hidpi scaling
devicePixelRatio: 1.0
logicalDpi: 96.3794466403 x 96.4556962025
physicalDpi: 93.7846153846 x 95.25
Using calibre Qt style: True
[0.00] Starting up...
[0.03] Showing splash screen...
[2.06] splash screen shown
[2.06] Initializing db...
[2.08] db initialized
[2.08] Constructing main UI...
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Looking for desktop notifier support from: org.freedesktop.Notifications
org.freedesktop.Notifications found in 0.0 seconds
[4.76] main UI initialized...
[4.76] Hiding splash screen
[5.11] splash screen hidden
[5.11] Started up in 5.11 seconds with 1 books

"First run"
Original Publisher: Blackmore Dennett
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher
Original Publisher: Test Publisher
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher

Also why would the print be repeated twice?

"and if I press the button again":

Original Publisher: Blackmore Dennett
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher
Original Publisher: Test Publisher
Updated Publisher: Test Publisher
Refreshed Publisher: Test Publisher

So it reads the old metadata back, not the new one? Is there any switch I need to flip to get changes actually written?
And would that write to the opf file or the database? (I checked both no updates)
Thanks guys
Einix is offline   Reply With Quote