Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 03-27-2011, 08:58 PM   #1
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,359
Karma: 5382313
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre's new plugin API

This is for plugin developers,

I just finished developing a new API for calibre plugins that makes coding plugins a lot easier/cleaner. The new API is backward compatible, i.e. old plugins should continue to work. It also fixes a bug where some users on windows with non ASCII paths were unable to load plugins, however for this fix to work for your plugin, you have to move it to use the new API.

Major features:

1. You can seamlessly import python code from different python files inside your plugin zip file using pythons normal import syntax, no more mucking around with zip import
2. A couple of new builtin functions that allow you to easy load images/data files from your plugin zip file
3. Point 1. means you no longer need the complicated structure of proxy classes in your InterfaceAction plugins


I also wrote a nice tutorial with sample plugins illustrating the techniques, available here: http://calibre-ebook.com/user_manual...g_plugins.html

Note that the example plugins have their minimum_calibre_version set to 0.7.53, so you either have to change the calibre version in your copy of the calibre source or wait for the next calibre release to actually run the plugins.

Let me know if you have any questions/concerns.

Last edited by kovidgoyal; 03-27-2011 at 09:04 PM.
kovidgoyal is offline   Reply With Quote
Old 03-27-2011, 09:01 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,359
Karma: 5382313
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Oh and if you have any suggestions on clarifying/improving the tutorial, do let me know.
kovidgoyal is offline   Reply With Quote
Old 03-27-2011, 09:27 PM   #3
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
I've updated the Introduction to plugins sticky to point to the new manual page.

The changes are very cool - looking forward to not having to maintain the 4,000 lines of Goodreads Sync plugin in a single file and reducing the repeated copy/paste of common plugin code. Plus of course hopefully reduced support issues from that nasty ZipImport error...

2 plugins converted, 14 remaining, sigh...
kiwidude is offline   Reply With Quote
Old 03-30-2011, 10:49 AM   #4
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
Hi Kovid,

After days of work I am finally down to the last plugin to be converted, and it is the most complex (Goodreads Sync). However I am having a problem trying to work out how to get the importing to work.

It relies on a library in a folder called “oauth2” which in turn uses another library “httplib2” which is a peer folder (as “httplib2” gets invoked directly by my code too).

I have added these two folders to your interface_demo project to replicate the scenario in simpler code you are familiar with, and added this line to ui.py:
import calibre_plugins.interface_demo.oauth2

The problem occurs within the __init__.py of oauth2, as it in turn on line 32 needs to resolve “import httplib2”.

I have tried all sorts of variations of modifying that line to for instance:
import calibre_plugins.interface_demo.httplib2

but nothing is working.

Help me Obi Wan...
Attached Files
File Type: zip interface_demo.zip (100.7 KB, 84 views)
kiwidude is offline   Reply With Quote
Old 03-30-2011, 11:18 AM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,359
Karma: 5382313
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You'll need to replace import httplib2 with

import calibre_plugins.interface_demo.httplib2 as httplib2

That should do the trick, if not, let me know.
kovidgoyal is offline   Reply With Quote
Old 03-30-2011, 11:32 AM   #6
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
I could have sworn I tried that... thanks Kovid, that works...
kiwidude is offline   Reply With Quote
Old 03-30-2011, 05:38 PM   #7
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Well I was 'this' close to another release, but I think I'll wait for 0.7.53 to come out so I can update to the new plugin api. In the meantime maybe I'll just add one more thing...
meme is offline   Reply With Quote
Old 03-30-2011, 05:57 PM   #8
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
@meme - well if you are running from source you could do the dev for it so you are ready to release this weekend

A straight migration of the code doesn't take too long - but if like me you decide to refactor it at the same time into separated code files and change your patterns for splitting the code it becomes rather non-trivial, I miss my C# refactoring tools, sigh. Plus you get no auto-completion assistance in Eclipse of any of your own code since it can't resolve the import statements. Then to round things off for me I found that Eclipse's IDE "Problems" parsing refused to work on many of my code files, so I may as well have been back to working in notepad for all the assistance it would give me in telling me about missing imports etc. I have no idea why Eclipse does that for some files and not others - not Kovid's problem I know!

I've finished converting them all now and done some testing but I wouldn't be surprised if I've introduced some bugs as careful as I tried to be. It will all pay off in the long term hopefully.
kiwidude is offline   Reply With Quote
Old 03-31-2011, 02:09 PM   #9
jackie_w
Wizard
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 2,884
Karma: 4200035
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
I have to admit to being a little intimidated by these changes, probably due to me being a rank amateur not a proper developer. I am going to take you at your word that the changes are backward compatible and that anyone using my plugin as-is will still be able to use it after v7.53 is released. I have no extra features currently planned.

Nevertheless, I am going to slowly try to get to grips with the changes which would need to be made to my very simple plugin. As a start I tried to download the sample from the manual but am getting
Code:
Forbidden
You don't have permission to access /downloads/interface_demo_plugin.zip on this server.
so I'm not off to a very good start.
jackie_w is offline   Reply With Quote
Old 03-31-2011, 02:17 PM   #10
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 26,359
Karma: 5382313
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
That was my mistake, try the download again, it should work now.
kovidgoyal is offline   Reply With Quote
Old 03-31-2011, 02:18 PM   #11
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
@jackie_w - assuming you have Calibre from source, just look in src\calibre\manual\plugin_examples\interface_demo

EDIT: I see Kovid posted a fix...
kiwidude is offline   Reply With Quote
Old 03-31-2011, 02:28 PM   #12
jackie_w
Wizard
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 2,884
Karma: 4200035
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
Download works now, thanks.

@kiwidude - I don't run from source. When I said "amateur" I really meant it

By the way, could you identify a simple (and preferably short) plugin which you have already upgraded so that I can get a better feel for what's going on.
jackie_w is offline   Reply With Quote
Old 03-31-2011, 02:50 PM   #13
kiwidude
calibre/Sigil Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,230
Karma: 1345754
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
I haven't uploaded any officially as yet of course, but here is the new version of my "Temp Marker" plugin which is a trivial one.

You can't install it without running from source and winding down the minimum_calibre_version (until 0.7.53 is released) but you can look through the code and compare with my original version which you can download from here.

I have a "Foo Example" plugin that I do some find/replace operations on as a starting point for each migration or new plugin that I write. The common_utils.py is a linked file that I share across my plugins containing common utility functions or UI stuff I reuse. I also have a batch file that I double-click on in Eclipse which builds the whole zip and runs it in Calibre, it looks like this for this plugin:

Code:
@ECHO OFF
pushd .
SET ZIPNAME=Temp Marker
cd "D:\CalibreDev\latest\calibre\src\calibre\plugins\%ZIPNAME%"

wzzip.exe -u -e0 "%ZIPNAME%.zip" ..\_CommonUtils\common_utils.py
wzzip.exe -u -e0 "%ZIPNAME%.zip" *.py
wzzip.exe -u -e0 "%ZIPNAME%.zip" *.txt
wzzip.exe -u -e0 -P -r "%ZIPNAME%.zip" images

calibre-customize -a "%ZIPNAME%.zip"
popd
SET ZIPNAME=
calibre-debug -g
For more complex plugins I split into additional code files, like a "dialogs.py" for any gui dialogs launched from the InterfaceAction. You will see it is almost identical to Kovid's example (except I put my InterfaceAction class in an "action.py" rather than "ui.py"). Being a rank amateur Python developer myself I am not averse to trying to copy from people who know what they are doing
Attached Files
File Type: zip Temp Marker.zip (21.2 KB, 81 views)
kiwidude is offline   Reply With Quote
Old 03-31-2011, 03:35 PM   #14
jackie_w
Wizard
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 2,884
Karma: 4200035
Join Date: Sep 2009
Location: UK
Device: Sony PRS-350, PB360, Kobo Glo/AuraHD/Aura6"/AuraH2O
@kiwidude,
Thank you. "Trivial" is the level I was hoping for.

There is no way you're a rank amateur! I use quite a few of your plugins - they're fantastic!
jackie_w is offline   Reply With Quote
Old 04-01-2011, 08:08 AM   #15
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
I'm trying to convert my plugin, and I've noticed while running from source I get errors like this for several dummy files even without running using my plugin - Calibre still runs though:

IndentationError: expected an indented block
Failed to initialize plugin...
Traceback (most recent call last):
File "/home/meme/Calibre-Source/calibre/src/calibre/customize/ui.py", line 486, in initialize_plugins
plugin = load_plugin(zfp) if not isinstance(zfp, type) else zfp
File "/home/meme/Calibre-Source/calibre/src/calibre/customize/ui.py", line 49, in load_plugin
return loader.load(path_to_zip_file)
File "/home/meme/Calibre-Source/calibre/src/calibre/customize/zipplugin.py", line 169, in load
m = importlib.import_module(plugin_module)
File "importlib/__init__.py", line 37, in import_module
File "/home/meme/Calibre-Source/calibre/src/calibre/customize/zipplugin.py", line 147, in load_module
import_name), 'exec', dont_inherit=True)
File "calibre_plugins.dummy12.__init__", line 38
print "HELLO!"
^

I've decided to split my code out into several files to make the most of the new api - it may be some time before it actually works again
meme is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] Plugin Updater **Deprecated** kiwidude Plugins 159 06-19-2011 01:27 PM
Metadata scraper plugin api kiwidude Development 5 03-06-2011 12:58 PM
Goodreads has published an API EricLandes Calibre 6 01-12-2011 05:39 PM
New Plugin Type Idea: Library Plugin cgranade Plugins 3 09-15-2010 01:11 PM
Ubook plugin api Dopedangel Reading and Management 0 08-25-2007 07:54 AM


All times are GMT -4. The time now is 01:24 AM.


MobileRead.com is a privately owned, operated and funded community.