MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Plugin Development (https://www.mobileread.com/forums/showthread.php?t=251452)

KevinH 11-23-2014 05:48 PM

Hi Doitsu,

Yes the "addotherfile" needs the book root relative href since it is for files outside the manifest. Anything in the manifest should be automatically put in the proper place by "addfile" unless I messed up someplace.

Take care,

KevinH

Toxaris 11-24-2014 02:28 PM

Another day, another question. I need to delete a file (a font) in the ePUB, so I use:
Code:

bk.deletefile(element[1])
The value of 'element[1]' is the manifest id, as it should. The strange thing is, that the manifest is correctly removed from the opf, but not the file itself. It still resides in the font folder. The internal check also does not report that there is an referenced file btw.

Is it a bug or am I doing something wrong?

Doitsu 11-24-2014 02:59 PM

@Toxaris: I was able to reproduce this bug. I also tried bk.deleteotherfile(), which removed the font from the Fonts folder in the Book View window, but not the actual epub file.

@KevinH: deleteotherfile() is defined as:

Code:

    def deleteotherfile(self, book_href):
        # removes file pointed to by the ebook href
        self._w.deleteotherfile(book_href)

IMHO, book_href should be replaced with id.

KevinH 11-24-2014 06:13 PM

Hi,

Quote:

Originally Posted by Doitsu (Post 2984909)
@Toxaris: I was able to reproduce this bug. I also tried bk.deleteotherfile(), which removed the font from the Fonts folder in the Book View window, but not the actual epub file.

@KevinH: deleteotherfile() is defined as:

Code:

    def deleteotherfile(self, book_href):
        # removes file pointed to by the ebook href
        self._w.deleteotherfile(book_href)

IMHO, book_href should be replaced with id.

No, book href is correct for deleteotherfile. It would be incorrect for deletefile.

Kevin

KevinH 11-24-2014 06:17 PM

Hi,
No actual deletes are done until the plugin completes. Only the fact you want to delete it should be recorded.

Perhaps there is a bug in the Sigil side not properly handling the delete or not properly updating the list of files in the viewer. Given it passes the check, we probably just need to update the viewer window inside Sigil.

I will look into this.

Thanks for the bug report!

Kevin

Quote:

Originally Posted by Toxaris (Post 2984877)
Another day, another question. I need to delete a file (a font) in the ePUB, so I use:
Code:

bk.deletefile(element[1])
The value of 'element[1]' is the manifest id, as it should. The strange thing is, that the manifest is correctly removed from the opf, but not the file itself. It still resides in the font folder. The internal check also does not report that there is an referenced file btw.

Is it a bug or am I doing something wrong?


Toxaris 11-24-2014 06:40 PM

Quote:

Originally Posted by KevinH (Post 2985098)
Hi,
No actual deletes are done until the plugin completes. Only the fact you want to delete it should be recorded.

Perhaps there is a bug in the Sigil side not properly handling the delete or not properly updating the list of files in the viewer. Given it passes the check, we probably just need to update the viewer window inside Sigil.

I will look into this.

Thanks for the bug report!

Kevin

That was my hunch as well, that the viewer was not updated. However, if I save the ePUB and reopen, the file is still there.

Doitsu 11-24-2014 07:18 PM

Quote:

Originally Posted by KevinH (Post 2985094)
No, book href is correct for deleteotherfile. It would be incorrect for deletefile.

You may want to double-check this one. If I use your improved code,

Code:

#!/usr/bin/env python
import os, inspect, uuid

def run(bk):
    SCRIPT_DIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    binary_file = 'WallauRundgotisch-Heavy.ttf'
    binary_path = os.path.join(SCRIPT_DIR, binary_file)
    data = ''
    with open(binary_path, 'rb') as f:
        data = f.read()
    uniqueid = 'id' + str(uuid.uuid4())[24:82]
    bk.addfile(uniqueid, binary_file, data, 'application/x-font-ttf')   

    return 0

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

if __name__ == "__main__":
    sys.exit(main())

a font file with the href Fonts/WallauRundgotisch-Heavy.ttf will be added.

However, if I subsequently, comment out the last line of the code, replace it with a bk.deleteotherfile() statement and use the above href as the parameter:

Code:

    #bk.addfile(uniqueid, binary_file, data, 'application/x-font-ttf')   
    bk.deleteotherfile('Fonts/WallauRundgotisch-Heavy.ttf')

I'm getting the following error message:

Code:

Traceback (most recent call last):
  File "/usr/local/share/sigil/plugin_launchers//python/launcher.py", line 137, in launch
    self.exitcode = target_script.run(container)
  File "/home/user/.local/share/sigil-ebook/sigil/plugins/test/plugin.py", line 13, in run
    bk.deleteotherfile('Fonts/WallauRundgotisch-Heavy.ttf')
  File "/usr/local/share/sigil/plugin_launchers/python/bookcontainer.py", line 143, in deleteotherfile
    self._w.deleteotherfile(book_href)
  File "/usr/local/share/sigil/plugin_launchers/python/wrapper.py", line 565, in deleteotherfile
    del self.id_to_filepath[id]
KeyError: u'Fonts/WallauRundgotisch-Heavy.ttf'
Error: u'Fonts/WallauRundgotisch-Heavy.ttf'

However, if I use the id instead of the href, I get no error message and the file is deleted both from the fonts folder and the manifest (but not from the actual epub file.)

D.

KevinH 11-24-2014 07:57 PM

Hi Doitsu,

Please do not try and delete files that exist in the manifest with the "other" family of interface calls.

deletefile
addfile
readfile
writefile

are all designed to work only on manifest files. The new version of the launcher code will enforce that.

Almost all files should be in the manifest. To access files not in the manifest such as container.xml, mimetype, OEBPS/content.opf etc, you would use the following interface routines:

readotherfile
writeotherfile
addotherfile
deleteotherfile

There is a serious bug in the deletefile interface in both the wrapper.py and in the launcher.py that I now have a fix for. I will post them in one minute so please hang on.

Thanks!

KevinH

KevinH 11-24-2014 08:06 PM

deletefile bug fix
 
Hi Toxaris and Doitsu,

There was a serious "thinko" in how I implemented how the plugin deletes files in the manifest that needed to be fixed. The previous version worked on files I added via plugin, but not on files that only existed in the original ebook.

I have now fixed that. Attached are two new versions of wrapper.py and launcher.py.

I have now committed them to my tree so hopefully they will be in time to make the upcoming release for Sigil 0.8.2

Also, since I can see that the launcher code needs to be updated faster that the Sigil main codebase (especially considering how many bugs you guys are finding!), I have developed a launcher_updater program, so that I can release launcher updates more frequently.

I have a rough working version of the launcher_updater but need to polish it before making my first release.

So until then, please grab and unzip the two files attached and add them to your plugin launcher code to replace their namesakes.

When Sigil 0.8.2 does come out, all of these changes will be included.

Please let me know if this does the trick.

KevinH

ps. DiapDealer just found and fixed another bug in deletefile so I have updated the wrapper.py yet again. When it rains it pours!!!

Toxaris 11-25-2014 06:42 AM

Great, will test it out tonight. With some luck I can polish it enough to be able to release my plugin tonight as well. It will be a font subsetter and image optimizer.

Toxaris 11-25-2014 12:07 PM

I get two errors in wrapper.py:
First a popup that says: Error parsing result XML: Premature end of document

Second the following error:
Traceback (most recent call last):
File "C:\Program Files\Sigil\plugin_launchers\\python\launcher.py", line 62, in <module>
from validationcontainer import ValidationContainer
ImportError: No module named validationcontainer

Of course I replaced both files you posted.

KevinH 11-25-2014 12:07 PM

Hi Toxaris,

Unfortunately there are changes inside Sigil that are needed to make this version work. I will modify something for you to test with that does not need Sigil to be changed and post it for you this evening.

Sorry about that, I am using and testing with a pre-release version of Sigil 0.8.2 and not the version you are using.

Kevin

KevinH 11-25-2014 12:17 PM

Hi Toxaris,

I stole a free moment at work to try and turn off the feature that allows plugin prints to appear immediately in the Sigil window. This feature requires changes in Sigil as well.

So please try the following version of launcher.py that should disable this new feature and hopefully work for you.

Sorry about that. I keep forgetting that Sigil 0.8.2 is not out yet!

KevinH

ps. To get around your second error you will need to add the following files to the plugin_launcher as well (after unzipping).

Doitsu 11-25-2014 01:16 PM

Unfortunately, the latest launcher version causes the following error message:

Code:

Traceback (most recent call last):
  File "/usr/local/share/sigil/plugin_launchers//python/launcher.py", line 30, in <module>
    from compatibility_utils import PY3, text_type, utf8_str, unicode_str, unescapeit

ImportError: cannot import name unescapeit


DiapDealer 11-25-2014 01:29 PM

Quote:

Originally Posted by Doitsu (Post 2985770)
Unfortunately, the latest launcher version causes the following error message:

Code:

Traceback (most recent call last):
  File "/usr/local/share/sigil/plugin_launchers//python/launcher.py", line 30, in <module>
    from compatibility_utils import PY3, text_type, utf8_str, unicode_str, unescapeit

ImportError: cannot import name unescapeit


Do you have the compatibility_utils installed? The latest one?

At this point, your best bet is to grab all the latest launcher files from Kevin's github and then replace launcher.py with the most recent one he posted in this thread. That's what I did with Sigil 0.8.1 and everything worked as it should.


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

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.