View Single Post
Old 07-18-2013, 10:32 AM   #1
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Using calibre.ebooks.oeb.polish.container in a driver

One of the suggestions for the Kobo driver has been a way to tweak the stylesheet during the send to device. There are a few things that Kobo does that would be nice to change. And while they could be edited into the ePubs, that means they are there for other devices which might not be desirable. The intention is to have a stylesheet in the root directory of the device and append that to any stylesheets in the ePub.

In fact, someone has written the code as a subclass of the KoboTouch driver and given me a copy. It works well and I am merging it into the KoboTouch driver. One thing it uses calibre.ebooks.oeb.polish.container. It has all the function necessary to find and modify the stylesheets.

But, I am getting an error when I run calibe from source. If I import the container where I use it, everything is OK. But, that means it will get imported each time a book is sent, which I assume will have a performance hit. If I put it at the top with the other imports, I get an error during startup when running from source. The statement added to the Kobo driver code is:

Code:
from calibre.ebooks.oeb.polish.container import get_container
The error is:

Code:
Python function terminated unexpectedly
  cannot import name plugin_for_input_format (Error Code: 1)
Traceback (most recent call last):
  File "site.py", line 132, in main
  File "site.py", line 109, in run_entry_point
  File "D:\Development\GitHub\calibre\src\calibre\debug.py", line 213, in main
    from calibre.gui2.main import main
  File "D:\Development\GitHub\calibre\src\calibre\gui2\main.py", line 18, in <module>
    from calibre.library.database2 import LibraryDatabase2
  File "D:\Development\GitHub\calibre\src\calibre\library\database2.py", line 30, in <module>
    from calibre.customize.ui import (run_plugins_on_import,
  File "D:\Development\GitHub\calibre\src\calibre\customize\ui.py", line 15, in <module>
    from calibre.customize.builtins import plugins as builtin_plugins
  File "D:\Development\GitHub\calibre\src\calibre\customize\builtins.py", line 669, in <module>
    from calibre.devices.kobo.driver import KOBO, KOBOTOUCH
  File "D:\Development\GitHub\calibre\src\calibre\devices\kobo\driver.py", line 30, in <module>
    from calibre.ebooks.oeb.polish.container import get_container
  File "D:\Development\GitHub\calibre\src\calibre\ebooks\oeb\polish\container.py", line 19, in <module>
    from calibre.customize.ui import (plugin_for_input_format,
ImportError: cannot import name plugin_for_input_format
I am assuming I have missed something, but can't see what it is. Can anyone tell me?

Of course, if there is another way of doing what I want that I have missed, that would be even better. I had a look, but couldn't find anything.
davidfor is offline   Reply With Quote