10-23-2010, 09:15 AM | #1 |
Sigil Developer
Posts: 8,076
Karma: 5450184
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 |
10-23-2010, 09:31 AM | #2 |
Sigil Developer
Posts: 8,076
Karma: 5450184
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 |
Advert | |
|
10-23-2010, 12:58 PM | #3 |
creator of calibre
Posts: 44,289
Karma: 23661992
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
try: import calibre in_calibre = True except ImportError: in_calibre = False |
10-23-2010, 08:17 PM | #4 |
Grand Sorcerer
Posts: 27,867
Karma: 198099188
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I found that:
Code:
if 'calibre' in sys.modules: inCalibre = True else: inCalibre = False |
Thread Tools | Search this Thread |
|
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 |