Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 02-28-2010, 09:13 AM   #1
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Plugins and optional Python modules

Calibre plugins seem to run with Calibre's python installation. How can I access an optional module that isn't installed in Calibre's python setup? E.g. PyCrypto?
pdurrant is offline   Reply With Quote
Old 02-28-2010, 10:06 AM   #2
rcuadro
Wizard
rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.
 
rcuadro's Avatar
 
Posts: 1,686
Karma: 874275
Join Date: Nov 2008
Location: Virginia Beach, VA
Device: Kindle DX
PyCrypto is a separate install and the following link may be of use:
http://dearauthor.com/wordpress/2010...-and-pycrypto/
rcuadro is offline   Reply With Quote
Advert
Old 02-28-2010, 10:22 AM   #3
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by rcuadro View Post
PyCrypto is a separate install and the following link may be of use:
http://dearauthor.com/wordpress/2010...-and-pycrypto/
Do you know if installing either Python or PyCrypto according to those instructions will interfere with Calibre in any way?
Starson17 is offline   Reply With Quote
Old 02-28-2010, 10:56 AM   #4
rcuadro
Wizard
rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.rcuadro ought to be getting tired of karma fortunes by now.
 
rcuadro's Avatar
 
Posts: 1,686
Karma: 874275
Join Date: Nov 2008
Location: Virginia Beach, VA
Device: Kindle DX
not at all...
rcuadro is offline   Reply With Quote
Old 02-28-2010, 10:58 AM   #5
Gunnerp245
Gadget Freak
Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.Gunnerp245 ought to be getting tired of karma fortunes by now.
 
Gunnerp245's Avatar
 
Posts: 1,169
Karma: 1043832
Join Date: Nov 2007
Location: US
Device: EE, Note 8
I have installed the 'complete' Windows Python environment - No issues with Calibre.

* For reference, Calibre was installed first, only because I was using it prior to the 'need' for the Python environment.

* Running Windows Vista Home Premium 32 bit.

Gunner...
Gunnerp245 is offline   Reply With Quote
Advert
Old 02-28-2010, 12:51 PM   #6
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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Stick it in the the plugin zip file. If your extra modules don't contain any compiled code (files ending with .so) that is all you need to do. If they do, the you have to unzip the zip file into a temporary directory and add that to sys.path in your plugin code.
kovidgoyal is offline   Reply With Quote
Old 02-28-2010, 01:14 PM   #7
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by kovidgoyal View Post
Stick it in the the plugin zip file. If your extra modules don't contain any compiled code (files ending with .so) that is all you need to do. If they do, the you have to unzip the zip file into a temporary directory and add that to sys.path in your plugin code.
Thanks! I'll give it a go.
pdurrant is offline   Reply With Quote
Old 02-28-2010, 06:02 PM   #8
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by kovidgoyal View Post
Stick it in the the plugin zip file. If your extra modules don't contain any compiled code (files ending with .so) that is all you need to do. If they do, the you have to unzip the zip file into a temporary directory and add that to sys.path in your plugin code.
I've had a go at this, and the module still isn't found. I tried taking the try: clause out from around the import statements, and now when I try to add the plug-in to Calibre I get

ERROR: ERROR: Unhandled exception: <b>ImportError</b>:No module named Crypto.Cipher

Traceback (most recent call last):
File "site-packages/calibre/gui2/dialogs/config/__init__.py", line 531, in add_plugin
File "site-packages/calibre/customize/ui.py", line 271, in add_plugin
File "site-packages/calibre/customize/ui.py", line 67, in load_plugin
File "<string>", line 34, in <module>
ImportError: No module named Crypto.Cipher


Looking at ui.py, line 67, it seems to me that at this point it has only decompressed the _plugin file, and not the module that's also included in the zip file. If it does a similar ting later when trying to execute, that would explain why things are not working.

Perhaps I'll need to do what you suggested later, and include the module as a zipped file, and explicitly unzip to a temporary folder and add to sys.path?

Or should it be working, and I've just done something wrong in adding in the module to the zip file?

Thanks.
pdurrant is offline   Reply With Quote
Old 02-28-2010, 07:02 PM   #9
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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
What happens is the following

Before the plugin is run by ui.py the path to the plugins zip file is added to sys.path

python can directly import python modules from zip files, but only python modules Not compiled modules like *.so or *.pyd files.

ANother thing to be aware of is that this happens only if you use the run_plugins_on_import function in ui.py
kovidgoyal is offline   Reply With Quote
Old 03-01-2010, 04:49 AM   #10
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by kovidgoyal View Post
Another thing to be aware of is that this happens only if you use the run_plugins_on_import function in ui.py
This sounds like it might be my problem, as the module I'm trying to use in my plug-in is pure python source code, with appropriate __init__.py files.

My zip file has this structure (folders in italic):

myplugin_plugin_zip
....myplugin_plugin.py
....Module
........__init__.py
........Submodule1
............__init__.py
............variousscripts.py
...........OtherFolders
...............__init__.py
........Submodule2

etc.

My plugin sets these up:

name = 'myplugin'
description = 'myplugin description'
supported_platforms = ['linux', 'osx', 'windows']
author = 'me'
version = (5, 0, 0)
file_types = set(['epub'])
on_import = True


What do I need to do to get the run_plugins_on_import function to run?

Hmm... Better still, I have trimmed everything from the plug-in, except an import of a function from a module. I hope I've got it all right, but there's very little code there, so hopefully I have. I attach the plugin.

What's wrong with this plug-in? When trying to add it, I get the error message "No module named TestModule"

I'm sorry if I'm missing something basic here.
Attached Files
File Type: zip moduletest_plugin.zip (3.0 KB, 567 views)
pdurrant is offline   Reply With Quote
Old 03-01-2010, 01:38 PM   #11
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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Stick the

from TestModule import TestFunction

into the run method

(the module will be in sys.path only during invocation of run, not during adding the plugin, etc.) and dont worry about run_plugins_on_import, in this case it is used automatically.

Also just so you know, the next release of calibre will automatically handle the case of plugins with compiled code as well as plugins with only python code.
kovidgoyal is offline   Reply With Quote
Old 03-01-2010, 02:30 PM   #12
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by kovidgoyal View Post
Stick the

from TestModule import TestFunction

into the run method
Oh - that makes sense. I'll give it a go with the test plugin and then with the real one. Many thanks.
pdurrant is offline   Reply With Quote
Old 03-01-2010, 03:26 PM   #13
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by pdurrant View Post
Oh - that makes sense. I'll give it a go with the test plugin and then with the real one. Many thanks.
And now I realise I made a silly mistake. The module I was looking at does have some compiled code. And so it's impossible (I think) to make a cross-platform plugin using it. Bother.

I suppose it would be possible to produce different versions, or perhaps instructions on how to add a module that's been compiled up separately by the user.

Hmm... that's not a bad idea. I'll give it a go.
pdurrant is offline   Reply With Quote
Old 03-01-2010, 09:10 PM   #14
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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
It's possible to make a plugin that is cross platform in this case as well.

What you do is the following (this will only work in the next release of calibre)

Put all three versions of the dependency in the plugin zip file, alongwith any needed dlls. Put them in subdirectories called

windows, osx, linux

Then in the run method of your plugin do this:

Code:
from calibre.constants import iswindows, isosx
pdir = 'windows' if iswindows else 'osx' if isosx else 'linux'
ppath = os.path.join(self.sys_insertion_path, pdir)
sys.insert(0, ppath)
try:
   import your_dependency
   plugin code
finally:
   sys.path.remove(ppath)
kovidgoyal is offline   Reply With Quote
Old 03-02-2010, 03:28 AM   #15
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,496
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by kovidgoyal View Post
It's possible to make a plugin that is cross platform in this case as well.

What you do is the following (this will only work in the next release of calibre)
Thanks again! I'll give it a go with the next release.
pdurrant is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional characters in Save Template for Adding Books Starson17 Calibre 1 02-28-2010 12:52 PM
Process Modules LarryLaser Calibre 3 02-10-2010 12:32 PM
question/suggestion: convert directly and make importing of sourcefile optional dura Calibre 0 09-09-2009 06:05 AM
iLiad USB serial modules drazvan iRex Developer's Corner 8 07-30-2007 05:43 PM
need a reader,bells and whistles optional Sandra Which one should I buy? 14 11-17-2005 02:49 AM


All times are GMT -4. The time now is 05:01 PM.


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