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 10-23-2010, 09:15 AM   #1
KevinH
Sigil Developer
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: 7,637
Karma: 5433388
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 offline   Reply With Quote
Old 10-23-2010, 09:31 AM   #2
KevinH
Sigil Developer
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: 7,637
Karma: 5433388
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 offline   Reply With Quote
Advert
Old 10-23-2010, 12: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: 43,844
Karma: 22666666
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, 08: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: 27,547
Karma: 193191846
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


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
Developer support JirkaS Calibre 16 11-23-2009 07:27 PM
New Developer Here infosprt Introduce Yourself 0 08-28-2008 07:10 PM
iLiad Developer Docs? triq200 iRex Developer's Corner 6 05-19-2008 10:12 AM
iLiad Cannot get Developer download talaivan iRex Developer's Corner 5 02-24-2008 07:54 PM


All times are GMT -4. The time now is 12:32 AM.


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