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

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-04-2012, 08:58 AM   #1
hakan42
Zealot
hakan42 is on a distinguished road
 
hakan42's Avatar
 
Posts: 136
Karma: 60
Join Date: Jul 2009
Location: Munich, Germany
Device: Nook Classic rooted; Galaxy S IV with Aldiko, other older devices
How do I instantiate new plugins?

For my current pet project ( just restarted work: Pluginize file naming strategy ), I need to configure a queue of plugins that need to be evaluated in order. One plugin (recreating the current Last name - First name strategy) would stay in the core of Calibre, others would be distributed as zip files like all the other plugins we already have.

Not having too much of python experience, I would imagine that for the configuration, I would store a list of class names in some json file.

For instantiation, I found the following code:

Code:
obj = eval(classname + "()")
somewhere on the 'net. Is this a proper practice? As mentioned above, the solution would need to work with code inside the calibre distribution as well as with plugins added via zip files.
hakan42 is offline   Reply With Quote
Old 01-04-2012, 09:06 AM   #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: 43,839
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Look at customize/ui.py to see how the various types of plugins are loaded in calibre. It should contain all the code you need to define your plugins.
kovidgoyal is offline   Reply With Quote
Advert
Old 01-20-2012, 01:36 PM   #3
hakan42
Zealot
hakan42 is on a distinguished road
 
hakan42's Avatar
 
Posts: 136
Karma: 60
Join Date: Jul 2009
Location: Munich, Germany
Device: Nook Classic rooted; Galaxy S IV with Aldiko, other older devices
Quote:
Originally Posted by kovidgoyal View Post
Look at customize/ui.py to see how the various types of plugins are loaded in calibre. It should contain all the code you need to define your plugins.
Thanks for your pointer, in the meantime I managed to create a new plugin type and add them to the "Plugins" menu. I also extracted a bit of code from database2.py and coverted it into a plugin. This class, I can instantiate with

Code:
from calibre.library.pathnames.byauthor.strategy import PathnameByAuthor
foo = PathnameByAuthor(self)
Two other plugins I wrote which conform to the API just defined, I can install into calibre via "calibre-customize -a <filename>.zip". The plugins contain the "plugin-import-name_<foo>.txt" file and __init__.py .

The part which I did not understand yet is how I would initialize such a class of which I might only know the plugin-import-name.
hakan42 is offline   Reply With Quote
Old 01-20-2012, 01:53 PM   #4
hakan42
Zealot
hakan42 is on a distinguished road
 
hakan42's Avatar
 
Posts: 136
Karma: 60
Join Date: Jul 2009
Location: Munich, Germany
Device: Nook Classic rooted; Galaxy S IV with Aldiko, other older devices
Quote:
Originally Posted by hakan42 View Post
The plugins contain the "plugin-import-name_<foo>.txt" file and __init__.py .

The part which I did not understand yet is how I would initialize such a class of which I might only know the plugin-import-name.
Nevermind, just found my own error

The plugin marker file needs a dash as last element, not an underscore. e.g.
Code:
plugin-import-name-<foo>.txt
and not
Code:
plugin-import-name_<foo>.txt
which is actually clearly written in http://manual.calibre-ebook.com/crea...terface-plugin
hakan42 is offline   Reply With Quote
Reply

Tags
database, directory name, directory_file_names, plugins

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating plugins paulfiera Plugins 2 11-04-2011 09:12 AM
Can't find my plugins? Kraftwerk Plugins 2 10-12-2011 05:07 PM
Plugins junkml Plugins 32 06-19-2009 06:43 AM
Plugins? Mitchll Plugins 0 12-27-2008 02:36 PM


All times are GMT -4. The time now is 02:35 PM.


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