Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 09-02-2017, 12:08 PM   #226
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: 8,837
Karma: 6120478
Join Date: Nov 2009
Device: many
The sys.path list can be appended to easily if done before importing a module, and the launcher wrapper has a self.appdir that will allow the path to the python3lib to be built on the fly easily (See EmbeddedPython.cpp embeddedRoot() routine - or something like that) on Windows and Mac. I am less sure where exactly on Linux the python3lib ends up depending on build settings.

So it would be easy to do with current code in a plugin on Windows and Mac, but I am not sure how easy it would be on Linux.

Diapdealer - is there any way to figure out where the python3lib is located in the current launcher or wrapper plugin code given what we pass in the sigil.cfg file?
KevinH is online now   Reply With Quote
Old 09-02-2017, 02:54 PM   #227
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: 28,643
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by KevinH View Post
Diapdealer - is there any way to figure out where the python3lib is located in the current launcher or wrapper plugin code given what we pass in the sigil.cfg file?
Not really from that cfg info, no.

And there's not a completely straightforward other way considering how many different ways Sigil can be installed on Linux, I should probably add Sigil's support file root location (typically /usr/share/sigil or /usr/local/share/sigil) to PluginRunner's cfg file that gets parsed by wrapper.py. But until that happens, Sigil's support file root location could be literally anywhere. It can be changed at compile-time or runtime.

However ... I believe the "plugin_launchers/python" directory is already added to every plugin's sys.path. If that can be identified, the python3lib directory is always going to be ../../python3lib from that one.

Something in here should get someone going in the meantime.

Code:
import sys, os

for path in sys.path:
    if "plugin_launchers/python" in path:
        print(path)
        sys.path.append(os.path.join(path, '../../python3lib'))
        print(sys.path)
        break
try:
    import ncxgenerator
    print('python3lib path', os.path.dirname(os.path.abspath(ncxgenerator.__file__)))
except ImportError:
    print('Can\'t find python3lib')

Last edited by DiapDealer; 09-02-2017 at 02:57 PM.
DiapDealer is offline   Reply With Quote
Advert
Old 09-02-2017, 04:37 PM   #228
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
@DiapDealer: Thanks for the code! After some cosmetic changes, it seems to work on all three platforms:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os

def run(bk):
    print(sys.path)
    for path in sys.path:
        if "plugin_launchers/python" or "plugin_launchers\\python" in path:
            print(path)
            sys.path.append(os.path.normpath(os.path.join(path, '../../python3lib')))
            print(sys.path)
            break
        
    try:
        import ncxgenerator
        print('python3lib path', os.path.dirname(os.path.abspath(ncxgenerator.__file__)))
    except ImportError:
        print('Can\'t find python3lib')
        
    return 0

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())
Doitsu is offline   Reply With Quote
Old 09-02-2017, 04:59 PM   #229
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: 28,643
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Great! Glad it works. If you don't want to loop though sys.path on Windows/Mac, remember that python3lib will always be:

os.path.join(bk._w.appdir, '../python3lib') -- for Mac
os.path.join(bk._w.appdir, 'python3lib') -- for Windows.
Attached Files
File Type: py plugin.py (1.3 KB, 406 views)
DiapDealer is offline   Reply With Quote
Old 09-02-2017, 05:05 PM   #230
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by DiapDealer View Post
Great! Glad it works. If you don't want to loop though sys.path on Windows/Mac, remember that python3lib will always be:

os.path.join(bk._w.appdir, '../python3lib') -- for Mac
os.path.join(bk._w.appdir, 'python3lib') -- for Windows.
Thanks again for the updated code!



I'll add it in the next version of the plugin.
Doitsu is offline   Reply With Quote
Advert
Old 09-02-2017, 06:53 PM   #231
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: 28,643
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I'll try to make sure and test the strategy on Linux with Sigil built/installed/and run in a variety of the possible configurations.
DiapDealer is offline   Reply With Quote
Old 10-05-2017, 10:30 AM   #232
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
@DiapDealer @KevinH

I'm working on a barebones edit plugin that'll delete unmanifested files from the Temp folder. It appears to be working fine. However, since deleting files in the Temp folder can crash Sigil, I'd appreciate it, if you could check the code.

EDIT: Unsupported and possibly dangerous code deleted.

Last edited by Doitsu; 10-16-2017 at 11:36 AM. Reason: Unsupported and possibly dangerous code deleted.
Doitsu is offline   Reply With Quote
Old 10-05-2017, 01:57 PM   #233
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: 28,643
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
It looks to be OK at first glance. You may want to add a try/except clause around the os.remove() call so that it can fail gracefully, though. An exception will be raised on Windows if the file in question happens to be open. Better safe than sorry.

Also ... I'm sure there's probably more "allowable" unmanifested files that will only become apparent after you've released your plugin (not that I can think of any offhand). A way for the user to exempt specific files (or file-types) might stave off future trouble.
DiapDealer is offline   Reply With Quote
Old 10-06-2017, 12:29 AM   #234
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by DiapDealer View Post
It looks to be OK at first glance. You may want to add a try/except clause around the os.remove() call so that it can fail gracefully, though.
That's a god idea. I'll add a try/except clause to check for locked backup files.

Quote:
Originally Posted by DiapDealer View Post
A way for the user to exempt specific files (or file-types) might stave off future trouble.
I can't think of any other "allowable" unmanifested file types. If this actually becomes an issue, I'll add a setting for it. (I don't think that the plugin'll be widely used anyway.)
Doitsu is offline   Reply With Quote
Old 10-06-2017, 12:36 AM   #235
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: 28,643
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Doitsu View Post
I can't think of any other "allowable" unmanifested file types. If this actually becomes an issue, I'll add a setting for it. (I don't think that the plugin'll be widely used anyway.)
Fair enough.
DiapDealer is offline   Reply With Quote
Old 12-10-2017, 11:32 AM   #236
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Expose the epub file name to Plugin API

Currently, it's pretty much impossible to get the name of currently opened file with Python. Some time ago, I investigated a rather complicated and not very reliable Windows-only method.

Since a Plugin Runner code update probably wouldn't be easy, I'm wondering about a different approach: would it be possible to have Sigil write the name of the epub file to the recentfile sigil.ini entry upon opening the epub file?
Plugin developers could then simply parse sigil.ini with configparser to get the file name. Since Sigil writes the file name to sigil.ini anyway whenever a file is closed this shouldn't require major code changes.
Doitsu is offline   Reply With Quote
Old 12-10-2017, 12:20 PM   #237
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: 8,837
Karma: 6120478
Join Date: Nov 2009
Device: many
The plugin runner actually builds a sigil.cfg file that the plugin launcher code parses to get appdir, dictionary and other paths for the wrapper code that are then added to the plugin interface. The correct way to handle this is to change MainWindow.cpp to add a routine to access m_CurrentFilePath, and use that new interface in PluginRunner to add this new path to the sigil.cfg and then add associated interface routines to the launcher/wrapper and then plugin type specific codes.

This involves quite a bit of work. So please explain why it is needed? Is this just to seed a possible name for output plugins? Why would an edit plugin need to know the name of the epub file as it can not be changed without messing up Sigil. Ditto for a validation plugin?
And input plugins are to load other files anyway so the current filename does not make much sense to me there either.

Kevin

Last edited by KevinH; 12-10-2017 at 12:24 PM.
KevinH is online now   Reply With Quote
Old 12-10-2017, 12:43 PM   #238
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by KevinH View Post
So please explain why it is needed? Is this just to seed a possible name for output plugins?
It'd be a nice-to-have feature for output plugins, but since it apparently would require a lot of work, it'd be better, if you used your limited time to work on enhancements.
Doitsu is offline   Reply With Quote
Old 12-10-2017, 12:53 PM   #239
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: 8,837
Karma: 6120478
Join Date: Nov 2009
Device: many
Wouldn't it be easier to recommend to users they add an html comment to the first file or define display:none header with the filename in the first file, or add a metadata element to the opf with that info and then invoke the output plugin? Your plugin could easily determine if the user has done this and if so read and use it otherwise default to a generic output filename.

Alternatively, parse the opf to get the main book title and remove unwanted/unsafe chars from it and use that as a suggested title.
KevinH is online now   Reply With Quote
Old 12-25-2017, 08:42 AM   #240
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,736
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
This may be a stupid question: is it possible to explicitly import book container functions such as bk.sigil_ui_lang() before run(bk) is executed?

If yes, what's the import declaration?
Doitsu is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Plugin in development Sladd Development 6 06-17-2014 06:57 PM
Question for plugin development gurus DiapDealer Plugins 2 02-04-2012 11:33 PM
DR800 Plugin development for DR800/DR1000 yuri_b iRex Developer's Corner 0 09-18-2010 09:46 AM
Device plugin development reader42 Plugins 10 03-29-2010 12:39 PM
Calibre plugin development - Newbie problems minstrel Plugins 5 04-12-2009 12:44 PM


All times are GMT -4. The time now is 09:24 AM.


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