11-23-2014, 05:48 PM | #16 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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 Last edited by KevinH; 11-23-2014 at 05:50 PM. |
11-24-2014, 02:28 PM | #17 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Another day, another question. I need to delete a file (a font) in the ePUB, so I use:
Code:
bk.deletefile(element[1]) Is it a bug or am I doing something wrong? |
Advert | |
|
11-24-2014, 02:59 PM | #18 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
@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) Last edited by Doitsu; 11-24-2014 at 03:32 PM. |
11-24-2014, 06:13 PM | #19 | |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
Hi,
Quote:
Kevin |
|
11-24-2014, 06:17 PM | #20 | |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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:
|
|
Advert | |
|
11-24-2014, 06:40 PM | #21 | |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
Quote:
|
|
11-24-2014, 07:18 PM | #22 | |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
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()) 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') 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' D. |
|
11-24-2014, 07:57 PM | #23 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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 Last edited by KevinH; 11-24-2014 at 09:00 PM. |
11-24-2014, 08:06 PM | #24 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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!!! Last edited by KevinH; 11-25-2014 at 04:27 PM. Reason: removed attachments see later launcher_modified.zip post |
11-25-2014, 06:42 AM | #25 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
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.
|
11-25-2014, 12:07 PM | #26 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
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. Last edited by Toxaris; 11-25-2014 at 12:11 PM. |
11-25-2014, 12:07 PM | #27 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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 |
11-25-2014, 12:17 PM | #28 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
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). Last edited by KevinH; 11-25-2014 at 04:27 PM. Reason: Removed incomplete fix - see later launcher_modifed.zip post for full set |
11-25-2014, 01:16 PM | #29 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
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 |
11-25-2014, 01:29 PM | #30 | |
Grand Sorcerer
Posts: 28,044
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
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. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 07:57 PM |
Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-05-2012 12:33 AM |
DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 10:46 AM |
Device plugin development | reader42 | Plugins | 10 | 03-29-2010 01:39 PM |
Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 01:44 PM |