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 01-08-2009, 09:46 PM   #1
dremo
Member
dremo began at the beginning.
 
Posts: 11
Karma: 18
Join Date: Jan 2009
Location: Minnesota
Device: PRS-505, iPhone 3GS, iPad
Run plugin before import

Is it possible for a plugin to run before the import is done? From tinkering around with a plugin it seems that the file is imported into the database and then the plugin runs.

I'd like to do some processing of a file before it is imported into Calibre. I would then like to have this processed file imported rather than the original file.

Other random question, is there a variable that stores the install path to calibre?


Thanks.
dremo is offline   Reply With Quote
Old 01-08-2009, 09:52 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: 25,276
Karma: 4961457
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
on_import = True causes the plugin to run just before the file is added to the database, but not before metadata is read from the file. If you want to change metadata reading, create a metadatareader plugin.

Getting the path to the calibre install directory is platform and installation method dependent. Here is some code to find the path to the plugins subdirectory ina calibre install

Code:
            if iswindows:
                plugin_path = os.path.join(os.path.dirname(sys.executable), 'plugins')
                sys.path.insert(1, os.path.dirname(sys.executable))
            elif isosx:
                plugin_path = os.path.join(getattr(sys, 'frameworks_dir'), 'plugins')
            elif islinux:
                plugin_path = os.path.join(getattr(sys, 'frozen_path'), 'plugins')
Note that you shouldn't need to know the path to the calibre install directory in your plugins.
kovidgoyal is offline   Reply With Quote
Old 01-08-2009, 09:56 PM   #3
dremo
Member
dremo began at the beginning.
 
Posts: 11
Karma: 18
Join Date: Jan 2009
Location: Minnesota
Device: PRS-505, iPhone 3GS, iPad
Thanks for the quick reply. The metadata I'm reading must be messed up. I never thought of trying a different file.



Drew
dremo is offline   Reply With Quote
Old 01-08-2009, 10:58 PM   #4
pilotbob
Grand Sorcerer
pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.
 
pilotbob's Avatar
 
Posts: 19,469
Karma: 11248282
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
Quote:
Originally Posted by kovidgoyal View Post
Getting the path to the calibre install directory is platform and installation method dependent. Here is some code to find the path to the plugins subdirectory ina calibre install
Sounds like a function that should be in calibre so it would be callable from a plugin.

BOb
pilotbob is offline   Reply With Quote
Old 01-08-2009, 11:01 PM   #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: 25,276
Karma: 4961457
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Quote:
Originally Posted by pilotbob View Post
Sounds like a function that should be in calibre so it would be callable from a plugin.

BOb

The problem is that the concept of "installation directory" is not well defined for a python program. Indeed, only the windows version could be said to have an "installation directory". Also plugins really shouldn't need to know where calibre is installed.
kovidgoyal is offline   Reply With Quote
Old 01-09-2009, 12:39 PM   #6
dremo
Member
dremo began at the beginning.
 
Posts: 11
Karma: 18
Join Date: Jan 2009
Location: Minnesota
Device: PRS-505, iPhone 3GS, iPad
Thanks for the help. I found my reason why the modifited file wasn't getting imported. I never updated the return statement to reflect the path of the updated file. Now it all seems to work, except the book name metadata isn't getting read correctly. All other fields seem correct except the book name.


Drew
dremo is offline   Reply With Quote
Old 01-09-2009, 12:40 PM   #7
pilotbob
Grand Sorcerer
pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.pilotbob ought to be getting tired of karma fortunes by now.
 
pilotbob's Avatar
 
Posts: 19,469
Karma: 11248282
Join Date: Jan 2007
Location: Tampa, FL USA
Device: Kindle Touch
Quote:
Originally Posted by kovidgoyal View Post
The problem is that the concept of "installation directory" is not well defined for a python program.
Gotcha ya. I guess I was thinking "startup" directory.

BOb
pilotbob 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
New Plugin Type Idea: Library Plugin cgranade Plugins 3 09-15-2010 12:11 PM
Referencer plugin IanHelgesen iRex 6 12-22-2008 09:24 PM
[Apple]Java Embedding Plugin 0.9.2: Force java to run in browsers other than Safari Zire Lounge 4 05-24-2005 09:12 PM


All times are GMT -4. The time now is 12:08 PM.


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