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 10-23-2010, 10:15 AM   #1
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 1,021
Karma: 444444
Join Date: Nov 2009
Device: many
Plugin Developer Question

Hi Kovid,

I have one piece of code that for support purposes, plays 3 roles. First it can be run standalone as a command line tool, second it can be imported into other python code (for code reuse) and last it can be a plugin for calibre.

I can use __name__ = '__main__' for detecting it as a standalone, but I need to a way to determine if imported from some other python code versus imported by the calibre python code.

So is there some string in __name__ that will definitely tell me I am being imported as a plugin from calibre code that won't change with where calibre is installed or from version to version of calibre (because keeping up with your release schedule would kill any normal human being).

Thanks,

KevinH
KevinH is online now   Reply With Quote
Old 10-23-2010, 10:31 AM   #2
KevinH
Wizard
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 1,021
Karma: 444444
Join Date: Nov 2009
Device: many
Hi,

Please ignore my question above. I ran some tests and __name__ does not in any way show the path through which the module is imported so I can't use it for what I want.

I will try and find something else on the python developer website that might tell me something. I guess I could always try and import something from the calibre plugin namespace in a try catch block and see if it succeeds or not.

Thanks,

Kevin
KevinH is online now   Reply With Quote
Old 10-23-2010, 01:58 PM   #3
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,350
Karma: 5382313
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Code:
try:
   import calibre
   in_calibre = True
except ImportError:
   in_calibre = False
kovidgoyal is offline   Reply With Quote
Old 10-23-2010, 09:17 PM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 9,424
Karma: 43260000
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I found that:
Code:
if 'calibre' in sys.modules:
   inCalibre = True
else:
   inCalibre = False
works rather nicely.
DiapDealer 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 01:11 PM
Developer support JirkaS Calibre 16 11-23-2009 08:27 PM
New Developer Here infosprt Introduce Yourself 0 08-28-2008 08:10 PM
iLiad Developer Docs? triq200 iRex Developer's Corner 6 05-19-2008 11:12 AM
iLiad Cannot get Developer download talaivan iRex Developer's Corner 5 02-24-2008 08:54 PM


All times are GMT -4. The time now is 07:17 PM.


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